답안 #578909

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
578909 2022-06-18T07:41:04 Z AGE Lutrija (COCI19_lutrija) C++14
0 / 70
879 ms 243636 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;
unordered_map<int,int>dist,p,okk;
map<int,vector<int>>adj;
int seive[N];
vector<int>primess;

bool is_prime(int x){

    for(int j=0;j<primess.size();j++){

            if(primess[j]*primess[j]>x)
                return 1;

            if(x%primess[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<=1e7;i++)
        if(seive[i]==0)
            primess.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);

    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(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]);

        }

    }

    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<primess.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:57: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]
   57 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
lutrija.cpp:62: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]
   62 |         for(int j=0;j<v.size();j++){
      |                     ~^~~~~~~~~
lutrija.cpp:116: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]
  116 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 798 ms 243516 KB Output is correct
2 Incorrect 817 ms 243480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 768 ms 243412 KB Output is correct
2 Incorrect 750 ms 243636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 757 ms 243360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 827 ms 243424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 792 ms 243476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 772 ms 243380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 879 ms 243540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 854 ms 243472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 872 ms 243460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 843 ms 243420 KB Output isn't correct
2 Halted 0 ms 0 KB -