Skip to content

Artemis: 'title': 'Improved performance and edge case handling in F1::run()' #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions f1.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <cstdint>
#include "f1.h"
#include <bits/stdc++.h>

Expand All @@ -11,36 +12,30 @@ typedef long long ll;

using namespace std;

bool F1::run()
{

bool F1::run() {
std::cout << "f1" << std::endl;

int N, K;

N = 10000;
K = 10000;
const int N = 10000;
const int K = 10000;

int total = ((N - 1) * (N - 2)) / 2;
if (K > total)
{
cout << -1 << endl;
return 0;
int64_t total = static_cast<int64_t>(N - 1) * (N - 2) / 2;
if (K > total) {
std::cout << -1 << std::endl;
return false;
}

vector<pair<int, int>> edges;
for (int i = 2; i <= N; ++i)
{
edges.push_back({1, i});
std::vector<std::pair<int, int>> edges;
edges.reserve(N - 1 + K);

for (int i = 2; i <= N; ++i) {
edges.emplace_back(1, i);
}

for (int i = 2; i < N && total > K; ++i)
{
for (int j = i + 1; j <= N && total > K; ++j, --total)
{
edges.push_back({i, j});
for (int i = 2; i < N && total > K; ++i) {
for (int j = i + 1; j <= N && total > K; ++j, --total) {
edges.emplace_back(i, j);
}
}

return true;
}
}
Empty file modified post_test.sh
100755 → 100644
Empty file.