結果

問題 No.12 限定された素数
ユーザー BantakoBantako
提出日時 2018-06-15 20:24:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 1,898 bytes
コンパイル時間 1,494 ms
コンパイル使用メモリ 165,828 KB
実行使用メモリ 8,544 KB
最終ジャッジ日時 2023-08-16 00:47:57
合計ジャッジ時間 5,745 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
8,340 KB
testcase_01 AC 122 ms
8,228 KB
testcase_02 AC 126 ms
8,312 KB
testcase_03 AC 124 ms
8,232 KB
testcase_04 AC 120 ms
8,272 KB
testcase_05 AC 121 ms
8,220 KB
testcase_06 AC 123 ms
8,236 KB
testcase_07 AC 121 ms
8,228 KB
testcase_08 AC 120 ms
8,312 KB
testcase_09 AC 122 ms
8,224 KB
testcase_10 AC 123 ms
8,340 KB
testcase_11 AC 123 ms
8,544 KB
testcase_12 AC 125 ms
8,280 KB
testcase_13 AC 123 ms
8,380 KB
testcase_14 AC 123 ms
8,220 KB
testcase_15 AC 128 ms
8,280 KB
testcase_16 AC 127 ms
8,428 KB
testcase_17 AC 126 ms
8,316 KB
testcase_18 AC 119 ms
8,212 KB
testcase_19 AC 122 ms
8,276 KB
testcase_20 AC 123 ms
8,288 KB
testcase_21 AC 122 ms
8,220 KB
testcase_22 AC 120 ms
8,236 KB
testcase_23 AC 122 ms
8,236 KB
testcase_24 AC 125 ms
8,288 KB
testcase_25 AC 122 ms
8,220 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   18 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;    
bool prime[5000001];//0 -> Prime
//nに含まれる数字をbit列で返す
int getbit(int n){
    int bit = 0;
    while(n > 0){
        bit |= (1 << (n % 10));
        n /= 10;
    }
    return bit;
}
main(){
    
    prime[0] = prime[1] = 1;
    for(int i = 2;i * i <= 5000001;i++){
        if(prime[i])continue;
        for(int j = i * 2;j <= 5000001;j += i){
            prime[j] = 1;
        }
    }
    /*
    vector< P > vec;
    rep(i,2,5000001){
        if(prime[i])continue;
        vec.emplace_back( P(i,getbit(i)) );
    }
    */
    int M,Bit = 0;
    cin >> M;
    rep(i,0,M){
        int a;
        cin >> a;
        Bit |= (1 << a);
    }
    //cout << bitset<10>(Bit) << endl;
    int N = 5000000;
    int ans = -1,l = 0,r = 0,b = 0;
    for(;l < N;r = l > r ? l : r){
        int rb = getbit(r);
        if(r < N && prime[r]){
            //cout << "a";
            //ans = max(ans, r - l);
            r++;
            //continue;
        }
        else if(r < N && (rb & Bit) == rb){
            //cout << "b";
            b |= rb;
            //ans = max(ans, r - l);
            r++;
        }else{
            //cout << "c";
            if(b == Bit)ans = max(ans, r - l - 1);
            b = 0;
            l++;
        }
        //cout << l << "," << r << " " << ans << ":" << bitset<10>(b) << endl;
    }
    if(b == Bit)ans = max(ans, r - l - 1);
    //ans = min(ans, 4999999);
    if(Bit == 0b100)ans = 1;
    cout << ans << endl;
    //cout << l << "," << r << endl;
    /*
    int n;
    while(1){
        cin >> n;
        //cout << bitset<10>(getbit(N)) << endl;
        //if(!prime[N])cout << "prime" << endl;
        //else         cout << "NotPrime" << endl;
    }
    */
}
0