Submission #735877

#TimeUsernameProblemLanguageResultExecution timeMemory
735877aykhnLutrija (COCI19_lutrija)C++14
70 / 70
293 ms304 KiB
#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 (stderr)

lutrija.cpp: In function 'bool f(std::vector<long long int>, std::vector<long long int>)':
lutrija.cpp:83:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |             for (ll i = 0; i < arr.size(); i++) cout << arr[i] << " ";
      |                            ~~^~~~~~~~~~~~
lutrija.cpp:89:1: warning: control reaches end of non-void function [-Wreturn-type]
   89 | }
      | ^
#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...