Submission #704768

# Submission time Handle Problem Language Result Execution time Memory
704768 2023-03-03T01:26:07 Z pcc Lutrija (COCI19_lutrija) C++14
70 / 70
366 ms 284 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
bool isp(ll k){
    if(k == 0)return false;
    if(k == 1)return false;
    for(ll i = 2;i*i<=k;i++){
        if(k%i == 0)return false;
    }
    return true;
}
map<ll,ll> mp;
int main(){
    ll a,b;
    cin>>a>>b;
    vector<ll> ans;
    bool rev = false;
    if(a>b){
        rev = true;
        swap(a,b);
    }
    ans.push_back(a);
    if(a == 2){
        if(isp(b+2)&&isp(b+2-a))ans = {2,b+2,b};
        else if(isp(b-2)&&isp(b-2-a))ans = {2,b-2,b};
        else{
            cout<<-1;
            return 0;
        }
    }
    else{
        ans.clear();
        vector<ll> va = {a};
        vector<ll> vb = {b};
        while(isp(va.back()-2))va.push_back(va.back()-2);
        while(isp(va.back()+2))va.push_back(va.back()+2);
        while(isp(vb.back()-2))vb.push_back(vb.back()-2);
        while(isp(vb.back()+2))vb.push_back(vb.back()+2);
        sort(va.begin(),va.end());
        va.erase(unique(va.begin(),va.end()),va.end());
        sort(vb.begin(),vb.end());
        vb.erase(unique(vb.begin(),vb.end()),vb.end());
        for(auto &i:va){
            if(!ans.empty())break;
            for(auto &j:vb){
                // cout<<i<<' '<<j<<endl;
                if(!ans.empty())break;
                if(isp(i-2)&&isp(j-2)){
                    ll ta = a,tb = j;
                    ans = {ta};
                    while(ta > i)ans.push_back(ta -=2);
                    while(ta < i)ans.push_back(ta += 2);
                    ans.push_back(2);
                    ans.push_back(tb);
                    while(tb > b)ans.push_back(tb -= 2);
                    while(tb < b)ans.push_back(tb += 2);
                }
                else if(i == j){
                    ans.push_back(a);
                    while(ans.back() != b)ans.push_back(ans.back()+2);
                }
            }
        }
    }
    if(ans.empty()||ans.back() != b){
        cout<<-1;
        return 0;
    }
    if(rev)reverse(ans.begin(),ans.end());
    cout<<ans.size()<<'\n';
    for(auto &i:ans)cout<<i<<' ';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 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 1 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 0 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 335 ms 276 KB Output is correct
2 Correct 84 ms 276 KB Output is correct
3 Correct 253 ms 280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 272 KB Output is correct
2 Correct 84 ms 284 KB Output is correct
3 Correct 179 ms 276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 272 KB Output is correct
2 Correct 82 ms 280 KB Output is correct
3 Correct 165 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 272 KB Output is correct
2 Correct 62 ms 212 KB Output is correct
3 Correct 60 ms 212 KB Output is correct