diff --git a/f1.cpp b/f1.cpp index 97ea106..1c6fd30 100644 --- a/f1.cpp +++ b/f1.cpp @@ -1,3 +1,4 @@ +#include #include "f1.h" #include @@ -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(N - 1) * (N - 2) / 2; + if (K > total) { + std::cout << -1 << std::endl; + return false; } - vector> edges; - for (int i = 2; i <= N; ++i) - { - edges.push_back({1, i}); + std::vector> 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; -} +} \ No newline at end of file diff --git a/post_test.sh b/post_test.sh old mode 100755 new mode 100644