結果

問題 No.774 tatyamと素数大富豪
ユーザー maimai
提出日時 2018-12-22 00:24:48
言語 cLay
(20231016-1)
結果
TLE  
実行時間 -
コード長 880 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 162,556 KB
実行使用メモリ 11,848 KB
最終ジャッジ日時 2023-09-19 00:17:05
合計ジャッジ時間 9,262 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

bool isprime(ll x){
    if (x <= 1) return false;
    if (x == 2) return true;
    if (x%2 == 0) return false;
    for (ll d = 3; d*d <= x; d+=2)
        if (x/d*d == x) return false;
    return true;
}


ll next_perm(vector<int>& buckets, ll val = 0) {
    bool empt = true;
    ll best = -1;
    REP(i, 13){
        if (buckets[i] == 0) continue;
        buckets[i]--;
        if (i <= 8)
            best = max(best, next_perm(buckets, val*10+(i+1)));
        else
            best = max(best, next_perm(buckets, val*100+(i+1)));
        buckets[i]++;
        empt = false;
    }
    
    if (empt)
        return isprime(val) ? val : -1;
    else
        return best;
}


int N;

{
    vector<int> buckets;
    rd(N);
    buckets.resize(13);
    REP(i, N){
        int a; rd(a);
        buckets[a-1]++;
    }
    
    ll ans;
    ans = next_perm(buckets);
    wt(ans);
    
}
0