Task: | Alkuluvut |
Sender: | cb14641 |
Submission time: | 2025-09-27 23:04:50 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 17 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 17 |
#2 | TIME LIMIT EXCEEDED | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
#2 | TIME LIMIT EXCEEDED | -- | 2, 3 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Code
#include <algorithm> #include <bits/stdc++.h> #include <random> using namespace std; typedef long long int ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<string> vs; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vl> vvl; #define all(x) x.begin(), x.end() #define rep(i, a, b) for (int i = a; i < b; i++) bool is_prime(ll x) { if (x <= 1 || (x > 2 && x % 2 == 0)) return false; for (int y = 3; y * y <= x; y += 2) if (x % y == 0) return false; return true; } void test() { int K; cin >> K; vi D(K); for (int k = 0; k < K; k++) cin >> D[k]; vb Db(10, false); for (int d : D) Db[d] = true; if (K == 1) { if (is_prime(D[0])) cout << "YES\n" + to_string(D[0]) + "\n"; else if (D[0] == 1) cout << "YES\n11\n"; else cout << "NO\n"; return; } if (K == 2) { if (Db[0] + Db[2] + Db[5] == 2) { cout << "NO\n"; return; } } if (K == 3) { if (Db[0] + Db[2] + Db[5] == 3) { cout << "NO\n"; return; } } random_device rd; mt19937 g(rd()); while (true) { vi D2(K); for (int k = 0; k < K; k++) D2[k] = D[k]; int extras = rand() % (16 - K); for (int e = 0; e < extras; e++) D2.push_back(D[rand() % K]); shuffle(D2.begin(), D2.end(), g); if (D2[0] == 0) continue; if (D2[D2.size() - 1] % 2 == 0) continue; ll sum = 0; for (int d : D2) sum += d; ll number = 0; for (int d : D2) number = number * 10 + d; // cout << "Trying " + to_string(number) + "\n"; if (is_prime(number)) { cout << "YES\n" + to_string(number) + "\n"; return; } } } void find_all() { vb found(1 << 10); while (true) { int x = rand(); if (!is_prime(x)) continue; } } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); int T; cin >> T; for (int t = 0; t < T; t++) test(); // find_all(); }
Test details
Test 1
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
10 1 0 1 1 ... |
correct output |
---|
NO YES 11 YES 2 ... |
user output |
---|
NO YES 11 YES 2 ... |
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) |