結果

問題 No.12 限定された素数
ユーザー 👑 NachiaNachia
提出日時 2020-09-27 13:17:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 5,000 ms
コード長 960 bytes
コンパイル時間 1,469 ms
コンパイル使用メモリ 164,700 KB
実行使用メモリ 28,020 KB
最終ジャッジ日時 2023-09-13 01:12:54
合計ジャッジ時間 4,985 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
27,700 KB
testcase_01 AC 72 ms
27,720 KB
testcase_02 AC 71 ms
27,788 KB
testcase_03 AC 64 ms
27,952 KB
testcase_04 AC 72 ms
27,832 KB
testcase_05 AC 71 ms
27,888 KB
testcase_06 AC 70 ms
27,808 KB
testcase_07 AC 68 ms
27,724 KB
testcase_08 AC 71 ms
27,780 KB
testcase_09 AC 71 ms
27,716 KB
testcase_10 AC 73 ms
27,808 KB
testcase_11 AC 66 ms
27,704 KB
testcase_12 AC 70 ms
27,720 KB
testcase_13 AC 71 ms
27,724 KB
testcase_14 AC 72 ms
27,720 KB
testcase_15 AC 71 ms
27,808 KB
testcase_16 AC 69 ms
27,784 KB
testcase_17 AC 72 ms
27,808 KB
testcase_18 AC 72 ms
27,832 KB
testcase_19 AC 71 ms
27,868 KB
testcase_20 AC 72 ms
28,016 KB
testcase_21 AC 73 ms
27,700 KB
testcase_22 AC 72 ms
28,020 KB
testcase_23 AC 72 ms
27,720 KB
testcase_24 AC 72 ms
27,792 KB
testcase_25 AC 71 ms
27,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const int Z = 5000000;
bool sieve[Z + 1];
int X[Z + 2];

int main() {
    sieve[0] = sieve[1] = true;
    for (int i = 2; i <= 3000; i++) {
        if (sieve[i]) continue;
        for (int j = i * i; j <= Z; j += i) sieve[j] = true;
    }

    rep(i, Z + 1) {
        if (sieve[i]) continue;
        int p = i;
        while (p) { X[i] |= (1 << (p % 10)); p /= 10; }
    }

    int N, V; cin >> N; V = 0;
    while (N--) { int a; cin >> a; V |= (1 << a); }
    rep(i, Z + 1) if (X[i] & ~V) X[i] = -1;
    X[0] = -1; X[Z + 1] = -1;

    int ans = -1;
    for (int i = 1; i <= Z + 1; i++) {
        if (X[i] != -1) continue;
        int tmp = 0, len = 0;;
        for (int j = i - 1; X[j] != -1; j--) { tmp |= X[j]; len++; }
        if (tmp == V) ans = max(ans, len - 1);
    }

    cout << ans << endl;

    return 0;
}
0