Submission #299185

# Submission time Handle Problem Language Result Execution time Memory
299185 2020-09-14T14:33:04 Z ryuku1110 Lutrija (COCI19_lutrija) C++14
0 / 70
3 ms 512 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
vector <int> adj[1001];
int a, b;
bool check(int x) {
    if (x == 0) return false;
    if (x == 1) return false;
    if (x == 2) return true;

    for (int i = 2; i <= sqrt(x); ++ i) 
        if (x % i == 0) return false;

    return true;
}

queue <int> q;
bool ok[1001];
int par[1001];
void bfs() {
    ok[a] = true;
    q.push(a);
    while (!q.empty()) {
        int u = q.back();
        q.pop();
        for (int v : adj[u]) {
            if (ok[v] == false) {
                par[v] = u;
                ok[v] = true;
                q.push(v);
            }
        }
    }
}
int d[3] = {0, 2, -2};
int main() {
    //freopen(".INP", "r", stdin);
    //freopen(".OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    memset(ok, false, sizeof(ok));
    cin >> a >> b;
    for (int i = 0; i < 3; ++ i) {
        for (int j = 0; j < 3; ++ j) {
            int u = a + d[i], v = b + d[j];
            if (check(u) == false || check(v) == false) continue;
            // cout << u << " " << v << endl;
            if (u > 0 && v > 0 && check(abs(v - u))) {
                adj[u].pb(v);
                adj[v].pb(u);
            } 
        }
    }
    for (int j = 0; j < 3; ++ j) {
        if (a + d[j] > 0 && check(a + d[j])) {
            adj[a].pb(a + d[j]);
            adj[a + d[j]].pb(a);
        }
        if (b + d[j] > 0 && check(b + d[j])) {
            adj[b].pb(b + d[j]);
            adj[b + d[j]].pb(b);
        }
    }
    bfs();
    if (ok[b]) {
        vector <int> ans;
        ans.pb(b);
        while (par[b] != 0) {
            ans.pb(par[b]);
            b = par[b];
        }
        cout << ans.size() << "\n";
        for (int i = ans.size() - 1; i >= 0; -- i) cout << ans[i] << " ";
        return 0;
    }
    cout << -1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -