Submission #578937

#TimeUsernameProblemLanguageResultExecution timeMemory
578937AGELutrija (COCI19_lutrija)C++14
42 / 70
2092 ms300 KiB
#include<bits/stdc++.h> #define F first #define S second #define int long long #define pb push_back using namespace std; const int N=1e6,M=2e3,mod=1e9+7; unordered_map<int,int>dist,p; map<int,vector<int>>adj; main(){ int a,b; cin>>a>>b; vector<int>v; v.pb(a); v.pb(b); v.pb(a-2); v.pb(a+2); v.pb(b+2); v.pb(b-2); v.pb(2); for(int i=0;i<v.size();i++){ int ok1=0; for(int k=2;k*k<=v[i];k++){ if(v[i]%k==0) ok1=1; } if(ok1==1) continue; for(int j=0;j<v.size();j++){ if(j==i||v[i]==v[j]||v[i]==1||v[j]==1||v[i]==0||v[j]==0) continue; ok1=0; for(int k=2;k*k<=v[j];k++){ if(v[j]%k==0) ok1=1; } if(ok1==1) continue; int x=abs(v[i]-v[j]); if(x==1||x==0) continue; int ok=0; for(int k=2;k*k<=x;k++){ if(x%k==0) ok=1; } if(ok==0) adj[v[i]].pb(v[j]),adj[v[j]].pb(v[i]); } } /*for(int i=0;i<v.size();i++){ cout<<v[i]<<": "; for(int j=0;j<adj[v[i]].size();j++) cout<<adj[v[i]][j]<<" "; cout<<endl; }*/ queue<int>q; dist[a]=1; q.push(a); while(!q.empty()){ int node=q.front(); q.pop(); for(auto x:adj[node]){ if(!dist[x]) q.push(x),dist[x]=1,p[x]=node; } } if(dist[b]==0) cout<<"-1"<<endl; else{ int node=b; vector<int>ans; while(node!=a) ans.pb(node),node=p[node]; ans.pb(a); reverse(ans.begin(),ans.end()); cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++){ cout<<ans[i]<<" "; } cout<<endl; } return 0; }

Compilation message (stderr)

lutrija.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      | ^~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:26:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
lutrija.cpp:35:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int j=0;j<v.size();j++){
      |                     ~^~~~~~~~~
lutrija.cpp:109:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         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...