# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
251535 | 2020-07-21T18:12:45 Z | MrRobot_28 | Lutrija (COCI19_lutrija) | C++17 | 347 ms | 384 KB |
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 10; vector <bool> used(N); vector <int> v, tmp, ans; int a, b; bool prost(int x) { if(x < 2) { return 0; } for(int j = 2; j * j <= x; j++) { if(x % j == 0) { return 0; } } return 1; } void dfs(int x) { used[x] = true; tmp.push_back(v[x]); if(v[x] == b){ if(ans.size() == 0 || ans.size() > tmp.size()) { ans = tmp; } tmp.pop_back(); return; } for(int i = 0; i < v.size(); i++) { if(!used[i] && prost(abs(v[x] - v[i]))) { dfs(i); used[i] = 0; } } tmp.pop_back(); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> a >> b; for(int i = a - 2; i <= a + 2; i++) { if(prost(i)) { v.push_back(i); } } for(int i = b - 2; i <= b + 2; i++) { if(prost(i)) { v.push_back(i); } } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for(int i = 0; i < v.size(); i++) { if(v[i] == a) { dfs(i); } } if(ans.size() == 0) { cout << -1; } else { cout << ans.size() << "\n"; for(int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Incorrect | 0 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Incorrect | 0 ms | 384 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 318 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 312 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 347 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 251 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |