# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
578939 |
2022-06-18T08:18:41 Z |
AGE |
Lutrija (COCI19_lutrija) |
C++14 |
|
1227 ms |
251716 KB |
#include<bits/stdc++.h>
#define F first
#define S second
#define int long long
#define pb push_back
using namespace std;
const int N=6e7,M=2e3,mod=1e9+7;
map<int,int>dist,p,okk;
map<int,vector<int>>adj;
int seive[N];
vector<int>ppprimess;
bool is_prime(int x){
for(int j=0;j<ppprimess.size();j++){
if(ppprimess[j]>=x)
return 1;
if((x%ppprimess[j])==0)
return 0;
}
return 1;
}
main(){
for(int i=2;i<=3e7;i++){
if(seive[i]==1)
continue;
for(int j=i+i;j<=3e7;j+=i)
seive[j]=1;
}
for(int i=2;i<=3e7;i++)
if(seive[i]==0)
ppprimess.pb(i);
vector<int>v;
int a,b;
cin>>a>>b;
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++){
if((is_prime(v[i])==0)||(v[i]==0)||(v[i]==1))
continue;
for(int j=0;j<v.size();j++){
if(i==j)
continue;
if((v[i]==v[j])||(is_prime(v[j])==0)||(v[j]==0)||(v[j]==1))
continue;
int x=abs(v[i]-v[j]);
if((is_prime(x)==0)||(x==0)||(x==1))
continue;
adj[v[i]].pb(v[j]);
adj[v[j]].pb(v[i]);
}
}
queue<int>q;
q.push(a);
dist[a]=1;
while(!q.empty()){
int node=q.front();
q.pop();
for(auto x:adj[node])
if(!dist[x])
dist[x]=1,q.push(x),p[x]=node;
}
if(dist[b]==0){
cout<<"-1"<<endl;
return 0;
}
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
lutrija.cpp: In function 'bool is_prime(long long int)':
lutrija.cpp:15: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]
15 | for(int j=0;j<ppprimess.size();j++){
| ~^~~~~~~~~~~~~~~~~
lutrija.cpp: At global scope:
lutrija.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
28 | main(){
| ^~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:59: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]
59 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
lutrija.cpp:64: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]
64 | for(int j=0;j<v.size();j++){
| ~^~~~~~~~~
lutrija.cpp:122: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]
122 | for(int i=0;i<ans.size();i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
876 ms |
251584 KB |
Output is correct |
2 |
Correct |
875 ms |
251592 KB |
Output is correct |
3 |
Correct |
782 ms |
251716 KB |
Output is correct |
4 |
Correct |
805 ms |
251688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
862 ms |
251596 KB |
Output is correct |
2 |
Correct |
789 ms |
251592 KB |
Output is correct |
3 |
Correct |
812 ms |
251616 KB |
Output is correct |
4 |
Correct |
803 ms |
251596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
811 ms |
251592 KB |
Output is correct |
2 |
Correct |
808 ms |
251596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
830 ms |
251588 KB |
Output is correct |
2 |
Correct |
804 ms |
251616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
845 ms |
251616 KB |
Output is correct |
2 |
Correct |
800 ms |
251592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
826 ms |
251592 KB |
Output is correct |
2 |
Correct |
968 ms |
251668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1225 ms |
251588 KB |
Output is correct |
2 |
Correct |
1063 ms |
251592 KB |
Output is correct |
3 |
Correct |
1126 ms |
251640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1183 ms |
251648 KB |
Output is correct |
2 |
Correct |
1116 ms |
251568 KB |
Output is correct |
3 |
Correct |
1147 ms |
251632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1227 ms |
251592 KB |
Output is correct |
2 |
Correct |
1034 ms |
251636 KB |
Output is correct |
3 |
Correct |
1181 ms |
251684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1211 ms |
251596 KB |
Output is correct |
2 |
Correct |
1006 ms |
251596 KB |
Output is correct |
3 |
Correct |
1118 ms |
251640 KB |
Output is correct |