Submission #251535

#TimeUsernameProblemLanguageResultExecution timeMemory
251535MrRobot_28Lutrija (COCI19_lutrija)C++17
0 / 70
347 ms384 KiB
#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 (stderr)

lutrija.cpp: In function 'void dfs(long long int)':
lutrija.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:67:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
lutrija.cpp:81:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < ans.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...