Submission #782222

# Submission time Handle Problem Language Result Execution time Memory
782222 2023-07-13T16:31:22 Z serifefedartar Lutrija (COCI19_lutrija) C++17
70 / 70
561 ms 304 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define LOGN 25
#define MAXN 200005

bool isPrime(ll x) {
    if (x <= 1)
        return false;

    for (ll i = 2; i * i <= x; i++)
        if (x % i == 0)
            return false;
    return true;
}

int main() {
    fast
    ll A, B;
    cin >> A >> B;
                       // 0   1   2   3    4   5   6
    vector<ll> cand_nodes{2, A-2, A, A+2, B-2, B, B+2};
    vector<ll> nodes;
    map<int,int> places;
    int no=1;
    for (auto u : cand_nodes) {
        if (isPrime(u)) {
            nodes.push_back(u);
            places[u] = no++;
        }
    }

    vector<ll> vis(10, false);
    queue<vector<ll>> q;
    q.push({A});
    while (!q.empty()) {
        vector<ll> path = q.front();
        q.pop();
        ll node = path.back();
        if (vis[places[node]])
            continue;
        vis[places[node]] = true;
        if (node == B) {
            cout << path.size() << endl;
            for (auto u : path)
                cout << u << " ";
            cout << endl;
            return 0;
        }

        for (auto u : nodes) {
            if (u != node && isPrime(abs(u - node))) {
                path.push_back(u);
                q.push(path);
                path.pop_back();
            }
        }
    }
    cout << -1 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 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
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 1 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 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 516 ms 300 KB Output is correct
2 Correct 191 ms 296 KB Output is correct
3 Correct 314 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 296 KB Output is correct
2 Correct 166 ms 300 KB Output is correct
3 Correct 226 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 561 ms 300 KB Output is correct
2 Correct 211 ms 296 KB Output is correct
3 Correct 207 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 417 ms 296 KB Output is correct
2 Correct 142 ms 296 KB Output is correct
3 Correct 74 ms 300 KB Output is correct