# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
217592 | 2020-03-30T10:25:39 Z | bayemirov | Lutrija (COCI19_lutrija) | C++17 | 350 ms | 480 KB |
//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; 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 256 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 4 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 323 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 340 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 350 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 257 ms | 480 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |