結果

問題 No.12 限定された素数
ユーザー otamay6otamay6
提出日時 2019-10-17 21:53:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 5,000 ms
コード長 1,053 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 175,428 KB
実行使用メモリ 6,036 KB
最終ジャッジ日時 2023-08-16 01:01:09
合計ジャッジ時間 7,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
5,872 KB
testcase_01 AC 171 ms
5,852 KB
testcase_02 AC 160 ms
5,724 KB
testcase_03 AC 142 ms
5,864 KB
testcase_04 AC 160 ms
5,808 KB
testcase_05 AC 179 ms
5,664 KB
testcase_06 AC 178 ms
6,036 KB
testcase_07 AC 177 ms
5,736 KB
testcase_08 AC 172 ms
5,856 KB
testcase_09 AC 170 ms
5,804 KB
testcase_10 AC 178 ms
5,804 KB
testcase_11 AC 168 ms
5,720 KB
testcase_12 AC 174 ms
5,800 KB
testcase_13 AC 175 ms
5,800 KB
testcase_14 AC 175 ms
5,676 KB
testcase_15 AC 174 ms
5,740 KB
testcase_16 AC 180 ms
5,876 KB
testcase_17 AC 153 ms
5,740 KB
testcase_18 AC 156 ms
5,800 KB
testcase_19 AC 156 ms
5,732 KB
testcase_20 AC 164 ms
5,688 KB
testcase_21 AC 169 ms
5,812 KB
testcase_22 AC 156 ms
5,684 KB
testcase_23 AC 156 ms
5,868 KB
testcase_24 AC 158 ms
5,864 KB
testcase_25 AC 179 ms
5,800 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    const int MAX=5e6+1;
    int N;cin>>N;
    set<int> must;
    REP(i,N){
        int a;cin>>a;
        must.insert(a);
    }
    vector<bool> sieve(MAX,true);
    vector<int> p;
    rep(i,2,MAX){
        if(sieve[i]){
            p.push_back(i);
            for(int j=i;j<=MAX;j+=i){
                sieve[j]=false;
            }
        }
    }
    int ans=-1,i=1,j=0;
    set<int> use;
    while(j<p.size()){
        int tmp=p[j];
        bool judge=true;
        while(tmp){
            if(!must.count(tmp%10)) judge=false;
            use.insert(tmp%10);
            tmp/=10;
        }
        
        if(!judge){
            i=p[j]+1;use.clear();
        }
        j++;
        if(use==must){
            if(j!=p.size()) ans=max(p[j]-1-i,ans);
            else ans=max(ans,MAX-1-i);
        }
    }
    cout<<ans<<endl;
}
0