# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
735877 | aykhn | Lutrija (COCI19_lutrija) | C++14 | 293 ms | 304 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
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;
}
if (!flag)
{
if (check(arr))
{
cout << arr.size() + 2 << endl;
cout << a << " ";
for (ll i = 0; i < arr.size(); i++) cout << arr[i] << " ";
cout << b << endl;
return true;
}
return false;
}
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |