답안 #735879

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
735879 2023-05-04T21:25:39 Z aykhn Lutrija (COCI19_lutrija) C++14
70 / 70
296 ms 340 KB
#include <bits/stdc++.h>


/*
    author: aykhn
    5/4/2023
*/

using namespace std;

typedef long long ll;

const int oo = INT_MAX;
const ll ooo = LONG_MAX;
const ll mod = 1e9 + 7;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define tos to_string
#define infll 0x3F3F3F3F3F3F3F3FLL
#define bpc __builtin_popcount

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

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

    return true;
}
ll a, b, n;
vector<ll> v;

bool check(vector<ll> &arr)
{
    ll l = arr.size();
    if (!l) return isPrime(abs(a - b));

    if (!isPrime(abs(arr[0] - a)) || !isPrime(abs(arr[l - 1] - b))) return false;

    for (ll i = 1; i < l; i++)
    {
        if (!isPrime(abs(arr[i] - arr[i - 1]))) return false;
    }
    cout << arr.size() + 2 << endl;
    cout << a << " ";
    for (ll i = 0; i < arr.size(); i++) cout << arr[i] << " ";
    cout << b << endl;
    return true;
}

bool f(vector<ll> arr, vector<ll> used)
{
    bool flag = 0;
    for (ll i = 0; i < n; i++)
    {
        if (used[i]) continue;
        flag = 1;
        used[i] = 1;
        arr.pb(v[i]);
        if (f(arr, used)) return true;
        arr.pop_back();
        if (f(arr, used)) return true;
        used[i] = 0;
    }

    return !flag && check(arr);
}

int main()
{
    cin >> a >> b;
    if (a != 2 && b != 2) v.pb(2);

    if (isPrime(a - 2)) v.pb(a - 2);
    if (isPrime(a + 2)) v.pb(a + 2);
    if (isPrime(b - 2)) v.pb(b - 2);
    if (isPrime(b + 2)) v.pb(b + 2);

    n = v.size();
    vector<ll> used(n, 0);
    vector<ll> arr;

    if (!f(arr, used))
    {
        cout << -1 << endl;
    }
    return 0;
}

Compilation message

lutrija.cpp: In function 'bool check(std::vector<long long int>&)':
lutrija.cpp:60:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (ll i = 0; i < arr.size(); i++) cout << arr[i] << " ";
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 273 ms 280 KB Output is correct
2 Correct 81 ms 212 KB Output is correct
3 Correct 165 ms 280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 264 ms 276 KB Output is correct
2 Correct 81 ms 212 KB Output is correct
3 Correct 118 ms 276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 296 ms 292 KB Output is correct
2 Correct 77 ms 212 KB Output is correct
3 Correct 112 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 216 ms 212 KB Output is correct
2 Correct 60 ms 280 KB Output is correct
3 Correct 44 ms 212 KB Output is correct