Submission #251631

#TimeUsernameProblemLanguageResultExecution timeMemory
251631terencehillLutrija (COCI19_lutrija)C++14
42 / 70
2092 ms524292 KiB
#include <bits/stdc++.h> #define all(X) (X).begin(),(X).end() #define rall(X) (X).rbegin(),(X).rend() #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define ff first #define ss second #define P 1000000007 #define in(x, a, b) (a <= x && x < b) using namespace std; using ll = long long; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vii> vvii; const ll inf = 1000000001, INF = (ll)1e18 + 1; bool isprime(ll x) { if(x == 0 || x == 1) return false; for(ll i = 2; i * i <= x; i++) if(x % i == 0) return false; return true; } ll a, b; vi vis, ans; vvi adj; vector<ll> primes; int done = 0; void dfs(int node) { if(done) return; if(vis[node]) return; vis[node] = 1; if(primes[node] == b) { cout << ans.size() << endl; for(int i : ans) cout << i << " "; cout << endl; done = 1; return; } for(int i : adj[node]) { ans.pub(primes[i]); dfs(i); ans.pob(); if(done) return; } if(done) return; } int main() { // freopen("INSERT_NAME_HERE.in", "r", stdin); // freopen("INSERT_NAME_HERE.out", "w", stdout); cin >> a >> b; for(int i = a - 2; i <= a + 2; i += 2) if(isprime(i)) primes.push_back(i); for(int i = b - 2; i <= b + 2; i += 2) if(isprime(i)) primes.push_back(i); primes.pub(2); sort(all(primes)); primes.erase(unique(all(primes)), primes.end()); adj.resize(primes.size()); vis.resize(primes.size(), 0); for(int i = 0; i < primes.size(); i++) { for(int j = i + 1; j < primes.size(); j++) { if(isprime(primes[j] - primes[i])) { adj[i].pub(j); adj[j].pub(i); } } } for(int i = 0; i < primes.size(); i++) { if(primes[i] == a) { ans.pub(a); dfs(i); break; } } if(!done) cout << -1 << endl; return 0; }

Compilation message (stderr)

lutrija.cpp: In function 'int main()':
lutrija.cpp:71:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < primes.size(); i++) {
                 ~~^~~~~~~~~~~~~~~
lutrija.cpp:72:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = i + 1; j < primes.size(); j++) {
                      ~~^~~~~~~~~~~~~~~
lutrija.cpp:80:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < primes.size(); i++) {
                 ~~^~~~~~~~~~~~~~~
#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...