Submission details
Task:Alkuluvut
Sender:sharph2
Submission time:2025-09-27 09:58:16 +0300
Language:C++ (C++17)
Status:READY
Result:58
Feedback
groupverdictscore
#1ACCEPTED17
#2ACCEPTED41
#30
Test results
testverdicttimegroup
#1ACCEPTED0.15 s1, 2, 3details
#2ACCEPTED0.15 s2, 3details
#30.15 s3details

Code

#include <algorithm>
#include <iostream>
#include <random>
#include <vector>

using namespace std;

using Z = long long int;

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    Z n = 10000000;
    vector<bool> yhdistetty(n);
    yhdistetty[0] = true;
    yhdistetty[1] = true;
    for(Z i = 2; i < n; ++i) {
        if(yhdistetty[i]) {
            continue;
        }
        for(Z j = 2 * i; j < n; j += i) {
            yhdistetty[j] = true;
        }
    }

    vector<Z> vastaus(1 << 10);
    vector<Z> alkuluvut;
    for(Z i = 0; i < n; ++i) {
        if(!yhdistetty[i]) {
            alkuluvut.push_back(i);
            Z v = i;
            Z numerot = 0;
            while(v != 0) {
                Z numero = v % 10;
                v /= 10;
                numerot |= (1 << numero);
            }
            if(!vastaus[numerot]) {
                vastaus[numerot] = i;
            }
        }
    }

    mt19937 rng;
    for(Z numerot = 0; numerot < (1 << 10); ++numerot) {
        if(vastaus[numerot]) {
            continue;
        }
        bool kaikki025 = true;
        bool kaikki3 = true;
        int epanollaLkm = 0;
        for(Z i = 0; i < 10; ++i) {
            if(numerot & (1 << i)) {
                if(i % 3) {
                    kaikki3 = false;
                }
                if((i & 1) && i != 5) {
                    kaikki025 = false;
                }
                if(i) {
                    ++epanollaLkm;
                }
            }
        }
        if(kaikki025 || kaikki3 || (numerot == (1 << 0) + (1 << 7))) {
            continue;
        }

        vector<Z> lst;
        for(Z i = 0; i < 10; ++i) {
            if(numerot & (1 << i)) {
                lst.push_back(i);
            }
        }

        if(lst.empty()) {
            throw 5;
        }

        vector<Z> jarj;
        while(true) {
            jarj = lst;
            Z toisto = uniform_int_distribution<Z>(0, 2)(rng);
            while(toisto --> 0) {
                jarj.push_back(lst[uniform_int_distribution<Z>(0, lst.size() - 1)(rng)]);
            }
            shuffle(jarj.begin(), jarj.end(), rng);
            if(jarj.back() == 0) {
                continue;
            }
            Z v = 0;
            for(Z i : jarj) {
                v *= 10;
                v += i;
            }
            if(v < 2) {
                continue;
            }
            bool kelpo = true;
            for(Z x : alkuluvut) {
                if(x * x > v) {
                    break;
                }
                if(v > x && v % x == 0) {
                    kelpo = false;
                    break;
                }
            }
            if(kelpo) {
                vastaus[numerot] = v;
                break;
            }
        }
    }

    Z t;
    cin >> t;

    for(Z ti = 0; ti < t; ++ti) {
        Z k;
        cin >> k;

        Z numerot = 0;
        for(Z i = 0; i < k; ++i) {
            Z v;
            cin >> v;
            numerot |= (1 << v);
        }

        if(vastaus[numerot]) {
            cout << "YES\n";
            cout << vastaus[numerot] << "\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:

input
848
4
0 1 2 3
4
0 1 2 4
...

correct output
YES
10223
YES
4021
YES
...

user output
YES
10223
YES
4021
YES
...