Submission #578937

# Submission time Handle Problem Language Result Execution time Memory
578937 2022-06-18T08:16:09 Z AGE Lutrija (COCI19_lutrija) C++14
42 / 70
2000 ms 300 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=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

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2067 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2092 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2076 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -