Task: | Alkuluvut |
Sender: | Gomhog |
Submission time: | 2025-09-28 13:59:40 +0300 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 17 |
#2 | ACCEPTED | 41 |
#3 | ACCEPTED | 42 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 2, 3 | details |
#3 | ACCEPTED | 0.38 s | 3 | details |
Code
#include <bits/stdc++.h> #define F first #define S second #define X real() #define Y imag() using namespace std; typedef long long ll; typedef long double ld; ll ans[16]; ll nums[16]; bool is_ok(int ind) { if (ans[ind-1]==0) return false; ll num =0; for (int i = ind-1; i>=0; i--) { num *= 10; num += ans[i]; } // cerr << num << endl; if (num < 2) return false; for (ll i = 2; i*i <= num; i++) { if (num % i == 0) return false; } return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tcs; cin>>tcs; for (int tc=0; tc<tcs;tc++) { int k; cin>>k; bool mulNum = false; for (int i=0;i<k;i++) { cin>>nums[i]; ans[i] = nums[i]; if (nums[i] == 1 || nums[i] ==3 || nums[i] == 7 || nums[i]==9) mulNum = true; } if (!mulNum && k>1) { cout<<"NO\n"; continue; } bool found = false; int ind = -1; for (int r=0;r<100;r++) { shuffle(ans,ans+k, default_random_engine(1337+r)); for (int top=k; top <= 11; top++) { if (is_ok(top)) { // cerr << "HEP" << endl; found=true; ind = top; break; } ans[top] = nums[rand()%k]; } if (found) break; } if (found) { cout<<"YES\n"; for (int i=0;i<ind;i++) cout<<ans[ind-i-1]; cout<<"\n"; } else cout<<"NO\n"; // return 0; } }
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: ACCEPTED
input |
---|
175 1 0 1 1 ... |
correct output |
---|
NO YES 11 YES 2 ... |
user output |
---|
NO YES 11 YES 2 ... |
Test 3
Group: 3
Verdict: ACCEPTED
input |
---|
848 4 0 1 2 3 4 0 1 2 4 ... |
correct output |
---|
YES 10223 YES 4021 YES ... |
user output |
---|
YES 3131232301 YES 210241 YES ... |