Submission #217597

#TimeUsernameProblemLanguageResultExecution timeMemory
217597bayemirovLutrija (COCI19_lutrija)C++17
70 / 70
771 ms508 KiB
//bayemirov #include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; #define pb push_back const ll INF = 1e9; const int d[] = {0, 2, -2}; map<ll, ll> dist, p; map<ll, vector<ll>> adj; vector<ll> v = {2}; ll a, b; bool isPrime(ll x) { if (x < 2) return 0; for (ll i = 2; i * i <= x; i++) if (x % i == 0) return 0; return 1; } void bfs() { for (auto x : v) dist[x] = INF; dist[a] = 0; queue<ll> q; q.push(a); while (!q.empty()) { ll v = q.front(); q.pop(); for (auto to : adj[v]) { if (dist[to] > dist[v] + 1) { dist[to] = dist[v] + 1; p[to] = v; q.push(to); } } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> a >> b; for (int i = 0; i < 3; i++) { if (isPrime(a+d[i])) v.pb(a+d[i]); if (isPrime(b+d[i])) v.pb(b+d[i]); } for (int i = 0; i < v.size(); i++) for (int j = 0; j < v.size(); j++) if (isPrime(abs(v[i]-v[j]))) adj[v[i]].pb(v[j]); bfs(); if (dist[b] == INF) cout << -1, exit(0); p[a] = -1; vector<ll> ans; while (b != -1) { ans.pb(b); b = p[b]; } reverse(ans.begin(), ans.end()); cout << ans.size() << "\n"; for (auto x : ans) cout << x << ' '; return 0; }

Compilation message (stderr)

lutrija.cpp: In function 'int main()':
lutrija.cpp:54:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < v.size(); i++)
                  ~~^~~~~~~~~~
lutrija.cpp:55:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < v.size(); j++)
                   ~~^~~~~~~~~~
#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...