| Task: | Alkuluvut |
| Sender: | ollpu |
| Submission time: | 2025-09-26 22:03:52 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| #2 | WRONG ANSWER | 0 |
| #3 | WRONG ANSWER | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | WRONG ANSWER | 0.14 s | 1, 2, 3 | details |
| #2 | TIME LIMIT EXCEEDED | -- | 2, 3 | details |
| #3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7+1;
bool z[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
vector<int> primes;
for (int i = 2; i < N; ++i) {
if (z[i]) continue;
primes.push_back(i);
for (int j = 2*i; j < N; j += i) z[j] = 1;
}
int T;
cin >> T;
for (int Ti = 0; Ti < T; ++Ti) {
int k;
cin >> k;
int ds[10] {};
for (int i = 0; i < k; ++i) {
int d;
cin >> d;
ds[d] = 1;
}
if (k == 1 && ds[1]) { cout << "YES\n11\n"; continue; }
if (k == 1 && ds[3]) { cout << "YES\n3\n"; continue; }
if (k == 1 && ds[7]) { cout << "YES\n7\n"; continue; }
if (k == 2 && ds[0]) { cout << "NO\n"; continue; }
if (ds[0] + ds[3] + ds[6] + ds[9] == k) { cout << "NO\n"; continue; }
int ld = 0;
for (int x : {1, 3, 7, 9}) {
if (ds[x]) ld = x;
}
if (!ld) { cout << "NO\n"; continue; }
string num;
for (int i = 0; i < 10; ++i) if (ds[i]) num.push_back('0'+i);
for (int i = 0; i < 10; ++i) if (ds[i] && i != ld) num.push_back('0'+i);
while (num.size() < 14) num.push_back('0'+ld);
if (stol(num) % 3 == 0) {
bool done = 0;
for (int i = 0; i < 10; ++i) {
if (ds[i] && (i-ld+9)%3) {
num[12] = '0'+i;
done = 1; break;
}
}
if (!done) num.pop_back();
}
while (true) {
random_shuffle(num.begin(), num.end()-1);
if (num[0] == '0') continue;
long n = stol(num);
bool f = 1;
for (int p : primes) {
if (n % p == 0) {
f = 0; break;
}
}
if (f) break;
}
cout << "YES\n";
cout << num << endl;
}
}
Test details
Test 1
Group: 1, 2, 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 1 0 1 1 ... |
| correct output |
|---|
| NO YES 11 YES 2 ... |
| user output |
|---|
| NO YES 11 NO YES ... |
Test 2
Group: 2, 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 175 1 0 1 1 ... |
| correct output |
|---|
| NO YES 11 YES 2 ... |
| user output |
|---|
| (empty) |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 848 4 0 1 2 3 4 0 1 2 4 ... |
| correct output |
|---|
| YES 10223 YES 4021 YES ... |
| user output |
|---|
| (empty) |
