Submission #645325

# Submission time Handle Problem Language Result Execution time Memory
645325 2022-09-26T19:23:44 Z Hacv16 Lutrija (COCI19_lutrija) C++17
0 / 70
5 ms 480 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e7 + 15;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << ": " << "[ " << x << " ]\n"

ll l, r, ind[MAX];
bool notPrime[MAX], inv, pos;
vector<ll> primes, ans;

void Crivo(ll n){
    notPrime[1] = true;

    for(int i = 2; i <= n; i++){
        if(notPrime[i]) continue;

        primes.push_back(i);

        ind[i] = sz(primes) - 1;

        for(int j = 2; i * j <= n; j++)
            notPrime[i * j] = true;
    }
}

void MakeforTwo(ll x, ll id){
    ans.push_back(x);
    if(x == 2){pos = true; return;}
    if(!notPrime[x - 2]) MakeforTwo(2, 0);

    ll diff = x - primes[id - 1];
    if(diff == 2) MakeforTwo(primes[id - 1], id - 1);
}

void MakeArray(ll x, ll id){
    ans.push_back(x);
    if(x == l){pos = true; return;}
    if(id == 0) return;

    ll diff = x - primes[id - 1];
    if(diff == 2) MakeArray(primes[id - 1], id - 1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    Crivo(1050);

    cin >> l >> r;

    if(l == 2 || r == 2){
        if(r == 2) swap(l, r), inv = true;
        MakeforTwo(r, ind[r]);

    }else{
        if(l > r) swap(l, r), inv = true;
        MakeArray(r, ind[r]);
    }

    if(!inv) reverse(all(ans));
    
    if(!pos){
        cout << -1 << '\n';

    }else{
        cout << sz(ans) << '\n';

        for(auto x : ans)
            cout << x << ' ';
            
        cout << '\n';
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 480 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 480 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -