답안 #578647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578647 2022-06-17T12:38:46 Z AGE Lutrija (COCI19_lutrija) C++14
0 / 70
2000 ms 304 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;
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++){
        for(int j=0;j<v.size();j++){

            if(j==i||v[i]==v[j])
                continue;
            int ok1=0;

            for(int k=2;k*k<=v[i];k++){
                if(v[i]%k==0)
                    ok1=1;
            }
            if(ok1==1)
                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)
                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]);

        }
    }

    for(int i=0;i<v.size();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(p[node]!=a)
            ans.pb(node),node=p[node];

        reverse(ans.begin(),ans.end());
        ans.pb(a);

        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:27: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]
   27 |         for(int j=0;j<v.size();j++){
      |                     ~^~~~~~~~~
lutrija.cpp:67: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]
   67 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
lutrija.cpp:68: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]
   68 |         for(int j=0;j<adj[v[i]].size();j++)
      |                     ~^~~~~~~~~~~~~~~~~
lutrija.cpp:105: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]
  105 |         for(int i=0;i<ans.size();i++){
      |                     ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 OK 1 ms 296 KB Checker has crashed
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 304 KB Integer parameter [name=array length] equals to 643, violates the range [-1, 30]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Integer parameter [name=array length] equals to 421, violates the range [-1, 30]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 304 KB Integer parameter [name=array length] equals to 349, violates the range [-1, 30]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2076 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2083 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2080 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2045 ms 256 KB Time limit exceeded
2 Halted 0 ms 0 KB -