# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735877 | 2023-05-04T21:23:55 Z | aykhn | Lutrija (COCI19_lutrija) | C++14 | 293 ms | 304 KB |
#include <bits/stdc++.h> /* author: aykhn 5/4/2023 */ using namespace std; typedef long long ll; const int oo = INT_MAX; const ll ooo = LONG_MAX; const ll mod = 1e9 + 7; #define OPT ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pii pair<int,int> #define pll pair<ll,ll> #define all(v) v.begin(), v.end() #define mpr make_pair #define pb push_back #define ts to_string #define fi first #define se second #define inf 0x3F3F3F3F #define tos to_string #define infll 0x3F3F3F3F3F3F3F3FLL #define bpc __builtin_popcount bool isPrime(ll a) { if (a <= 1) return false; for (ll i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } ll a, b, n; vector<ll> v; bool check(vector<ll> &arr) { ll l = arr.size(); if (!l) return isPrime(abs(a - b)); if (!isPrime(abs(arr[0] - a)) || !isPrime(abs(arr[l - 1] - b))) return false; for (ll i = 1; i < l; i++) { if (!isPrime(abs(arr[i] - arr[i - 1]))) return false; } return true; } bool f(vector<ll> arr, vector<ll> used) { bool flag = 0; for (ll i = 0; i < n; i++) { if (used[i]) continue; flag = 1; used[i] = 1; arr.pb(v[i]); if (f(arr, used)) return true; arr.pop_back(); if (f(arr, used)) return true; used[i] = 0; } if (!flag) { if (check(arr)) { cout << arr.size() + 2 << endl; cout << a << " "; for (ll i = 0; i < arr.size(); i++) cout << arr[i] << " "; cout << b << endl; return true; } return false; } } int main() { cin >> a >> b; if (a != 2 && b != 2) v.pb(2); if (isPrime(a - 2)) v.pb(a - 2); if (isPrime(a + 2)) v.pb(a + 2); if (isPrime(b - 2)) v.pb(b - 2); if (isPrime(b + 2)) v.pb(b + 2); n = v.size(); vector<ll> used(n, 0); vector<ll> arr; if (!f(arr, used)) { cout << -1 << endl; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 296 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 296 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 274 ms | 276 KB | Output is correct |
2 | Correct | 81 ms | 212 KB | Output is correct |
3 | Correct | 163 ms | 276 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 272 ms | 276 KB | Output is correct |
2 | Correct | 84 ms | 280 KB | Output is correct |
3 | Correct | 118 ms | 304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 293 ms | 280 KB | Output is correct |
2 | Correct | 80 ms | 276 KB | Output is correct |
3 | Correct | 119 ms | 276 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 218 ms | 284 KB | Output is correct |
2 | Correct | 60 ms | 284 KB | Output is correct |
3 | Correct | 40 ms | 212 KB | Output is correct |