Submission #1089539

#TimeUsernameProblemLanguageResultExecution timeMemory
1089539GervidLutrija (COCI19_lutrija)C++17
42 / 70
1589 ms524288 KiB
#include <iostream> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <limits.h> #include <algorithm> #include <math.h> using namespace std; set<long long> been; vector<long long> out; bool isprime(long long n) { for (long long i = 2; i*i <= n; i++) { if (n % i == 0) return false; } return true; } bool dfs(int node, int goal) { if (node == goal) { out.push_back(node); return true; } for (long long neighbour : {2, node + 2, node - 2 > 2 ? node - 2 : 4}) { if (!been.count(neighbour) && isprime(neighbour) && isprime(abs(node - neighbour))) { been.insert(neighbour); if (dfs(neighbour, goal)) { out.push_back(node); return true; } } } return false; } int main() { iostream::sync_with_stdio(0); cin.tie(0); long long a, b; cin >> a >> b; if (!dfs(a, b)) {//need to go down to 2, or not possible if (been.count(2)) { been.clear(); dfs(b, a); if (been.count(2)) { out.clear(); been.clear(); dfs(a, 2); vector<long long> firsthalf; out.swap(firsthalf); been.clear(); dfs(b, 2); cout << out.size() + firsthalf.size() - 1 << '\n'; for (int i = firsthalf.size() - 1; i > 0; i--) { cout << firsthalf[i] << ' '; } for (int i = 0; i < out.size(); i++) { cout << out[i] << ' '; } return 0; } } cout << -1; return 0; } cout << out.size() << '\n'; for (int i = out.size() - 1; i >= 0; i--) { cout << out[i] << ' '; } }

Compilation message (stderr)

lutrija.cpp: In function 'int main()':
lutrija.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for (int i = 0; i < out.size(); i++)
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...