답안 #445333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445333 2021-07-17T13:56:06 Z colossal_pepe Lutrija (COCI19_lutrija) C++17
70 / 70
1722 ms 288 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<ll> 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<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for (int i = 1; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 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 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1576 ms 268 KB Output is correct
2 Correct 289 ms 288 KB Output is correct
3 Correct 96 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1541 ms 268 KB Output is correct
2 Correct 281 ms 272 KB Output is correct
3 Correct 69 ms 268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1722 ms 268 KB Output is correct
2 Correct 285 ms 268 KB Output is correct
3 Correct 65 ms 268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1259 ms 268 KB Output is correct
2 Correct 208 ms 204 KB Output is correct
3 Correct 23 ms 204 KB Output is correct