Submission #1029311

# Submission time Handle Problem Language Result Execution time Memory
1029311 2024-07-20T16:12:54 Z 0pt1mus23 Lutrija (COCI19_lutrija) C++14
0 / 70
23 ms 604 KB
#pragma GCC optimize("O3", "inline")
#define skillissue <bits/stdc++.h>
#define ultra_mal std
#include skillissue
using namespace ultra_mal;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n' 
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
#define hash FhashF
const int mod = 1e9 +7, sze = 1E3 +100, inf = LLONG_MAX, P = 1453;
// const int L = 30;

int prime(int aa){
    for(int i = 2;i*i<=aa;i++){
        if(aa%i==0){
            return 0;        
        }
    }

    return 1;
}

void cave(){
    int x,y;
    cin>>x>>y;
    int lim =1e15;
    vector<int> ans;
    if((x&1)==(y&1)){
        if((x&1)){

            vector<int> az;
            vector<int> art;


            az.pb(x);
            bool flag=false;
            while(az.size()<29){
                if(az.back()<=2){
                    break;
                }
                az.pb(az.back()-2);
                int a = az.back();
                if(a==y){
                    az.pop_back();
                }
                else{
                    if(!prime(a)){
                        break;
                    }
                }

                if(prime(abs(y-a))){
                    az.pb(y);
                    cout<<az.size()<<endl;
                    for(auto v:az){
                        cout<<v<<" ";
                    }
                    cout<<endl;
                    return;
                }
            }


            art.pb(x);
            while(art.size()<29){
                if(art.back()+2>lim){
                    break;
                }
                art.pb(art.back()+2);
                int a = art.back();
                if(a==y){
                    art.pop_back();
                }
                else{
                    if(!prime(a)){
                        break;
                    }
                }

                if(prime(abs(y-a))){
                    art.pb(y);
                    cout<<art.size()<<endl;
                    for(auto v:art){
                        cout<<v<<" ";
                    }
                    cout<<endl;
                    return;
                }
            }


            
        }
        else{
            drop(-1);
        }
    }
    else{
        // biri cut, biri tek
        int xx = x;
        int yy = y;
        if(min(xx,yy)>2){
            drop(-1);
        }
        if(y&1){
            swap(x,y);
        }

        vector<int> az;
        vector<int> art;


        az.pb(x);
        bool flag=false;
        while(az.size()<29){
            if(az.back()<=2){
                break;
            }
            az.pb(az.back()-2);
            int a = az.back();
            if(a==y){
                az.pop_back();
            }
            else{
                if(!prime(a)){
                    break;
                }
            }

            if(prime(abs(y-a))){
                az.pb(y);
                cout<<az.size()<<endl;
                if(az[0]!=xx){
                    reverse(all(az));
                }
                for(auto v:az){
                    cout<<v<<" ";
                }
                cout<<endl;
                return;
            }
        }


        art.pb(x);
        while(art.size()<29){
            if(art.back()+2>lim){
                break;
            }
            art.pb(art.back()+2);
            int a = art.back();
            if(a==y){
                art.pop_back();
            }
            else{
                if(!prime(a)){
                    break;
                }
            }

            if(prime(abs(y-a))){
                art.pb(y);
                if(art[0]!=xx){
                    reverse(all(art));
                }
                cout<<art.size()<<endl;
                for(auto v:art){
                    cout<<v<<" ";
                }
                cout<<endl;
                return;
            }
        }

        

    }

    drop(-1);

    
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int tt = 1;
    // cin>>tt;
    
    while(tt--){
        cave();
    }

    return 0;
} 
 

Compilation message

lutrija.cpp: In function 'void cave()':
lutrija.cpp:42:18: warning: unused variable 'flag' [-Wunused-variable]
   42 |             bool flag=false;
      |                  ^~~~
lutrija.cpp:120:14: warning: unused variable 'flag' [-Wunused-variable]
  120 |         bool flag=false;
      |              ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 456 KB Output isn't correct
2 Halted 0 ms 0 KB -