Submission #445331

# Submission time Handle Problem Language Result Execution time Memory
445331 2021-07-17T13:52:44 Z colossal_pepe Lutrija (COCI19_lutrija) C++17
42 / 70
1 ms 204 KB
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

ll a, b, ans[5];

bool isPrime(ll x) {
    if (x < 2) return 0;
    for (ll i = 2; i * i <= x; i++) {
        if (x%i == 0) return 0;
    }
    return 1;
}

bool check() {
    vector<int> v;
    for (ll i: ans) {
        if (i > 0) v.push_back(i);
    }
    for (int i = 1; i < v.size(); i++) {
        if (not isPrime(v[i]) or not isPrime(abs(v[i] - v[i - 1]))) return 0;
    }
    return 1;
}

bool solve() {
    ans[0] = a, ans[4] = b;
    ll c1[3] = {0, a - 2, a + 2}, c2[2] = {0, 2}, c3[4] = {0, b - 2, b + 2};
    for (ll p: c1) {
        for (ll q: c2) {
            for (ll r: c3) {
                ans[1] = p, ans[2] = q, ans[3] = r;
                if (check()) return 1;
            }
        }
    }
    return 0;
}

int main() {
    cin >> a >> b;
    if (solve()) {
        int cnt = 0;
        for (ll i: ans) {
            if (i > 0) cnt++;
        }
        cout << cnt << endl;
        for (ll i: ans) {
            if (i > 0) cout << i << ' ';
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Compilation message

lutrija.cpp: In function 'bool check()':
lutrija.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 1; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -