結果
問題 | No.12 限定された素数 |
ユーザー | monnu |
提出日時 | 2021-07-13 21:58:15 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 163 ms / 5,000 ms |
コード長 | 1,701 bytes |
コンパイル時間 | 3,832 ms |
コンパイル使用メモリ | 228,460 KB |
実行使用メモリ | 29,760 KB |
最終ジャッジ日時 | 2023-09-15 14:25:32 |
合計ジャッジ時間 | 9,357 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 156 ms
29,588 KB |
testcase_01 | AC | 156 ms
29,636 KB |
testcase_02 | AC | 156 ms
29,504 KB |
testcase_03 | AC | 156 ms
29,508 KB |
testcase_04 | AC | 157 ms
29,512 KB |
testcase_05 | AC | 163 ms
29,520 KB |
testcase_06 | AC | 159 ms
29,652 KB |
testcase_07 | AC | 159 ms
29,512 KB |
testcase_08 | AC | 159 ms
29,456 KB |
testcase_09 | AC | 157 ms
29,704 KB |
testcase_10 | AC | 159 ms
29,760 KB |
testcase_11 | AC | 161 ms
29,464 KB |
testcase_12 | AC | 160 ms
29,460 KB |
testcase_13 | AC | 159 ms
29,456 KB |
testcase_14 | AC | 158 ms
29,656 KB |
testcase_15 | AC | 159 ms
29,520 KB |
testcase_16 | AC | 160 ms
29,724 KB |
testcase_17 | AC | 156 ms
29,696 KB |
testcase_18 | AC | 157 ms
29,568 KB |
testcase_19 | AC | 158 ms
29,708 KB |
testcase_20 | AC | 157 ms
29,460 KB |
testcase_21 | AC | 158 ms
29,464 KB |
testcase_22 | AC | 162 ms
29,516 KB |
testcase_23 | AC | 156 ms
29,652 KB |
testcase_24 | AC | 157 ms
29,720 KB |
testcase_25 | AC | 161 ms
29,464 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll=long long; #define MOD 998244353 using Graph=vector<vector<int>>; #define INF 1000000000 #define MAX 5000000 vector<int> p; vector<bool> p_table(MAX+1,true); void prime(){ p_table.at(0)=false,p_table.at(1)=false; for(int i=2;i<=MAX;i++){ if(p_table.at(i)){ p.push_back(i); for(int j=2;i*j<=MAX;j++){ p_table.at(i*j)=false; } } } } int main(){ int N; cin>>N; vector<bool> A(10,false); for(int i=0;i<N;i++){ int a; cin>>a; A[a]=true; } prime(); int n=p.size(); vector<vector<int>> cnt(n+1,vector<int>(10,0)); for(int i=0;i<n;i++){ int x=p[i]; for(int j=0;j<10;j++){ cnt[i+1][j]+=cnt[i][j]; } while(x>0){ cnt[i+1][x%10]++; x/=10; } } int ans=-1; for(int i=0;i<n;i++){ int left=i+1; int right=n+1; while(left+1<right){ int x=(left+right)/2; int count=0; for(int j=0;j<10;j++){ if(cnt[x][j]-cnt[i][j]>0){ count++; } } if(count<=N){ left=x; }else{ right=x; } } bool flag=true; int x=left; for(int j=0;j<10;j++){ if(A[j]==true){ if(cnt[x][j]-cnt[i][j]==0){ flag=false; } }else{ if(cnt[x][j]-cnt[i][j]>0){ flag=false; } } } if(flag==true){ if(i==0&&x==n){ ans=max(ans,5000000-1); }else if(i==0){ ans=max(ans,p[x]-1-1); }else if(x==n){ ans=max(ans,5000000-p[i-1]-1); }else{ ans=max(ans,p[x]-1-p[i-1]-1); } } } cout<<ans<<endl; }