結果
問題 | No.12 限定された素数 |
ユーザー |
![]() |
提出日時 | 2021-10-20 21:23:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 284 ms / 5,000 ms |
コード長 | 1,055 bytes |
コンパイル時間 | 4,898 ms |
コンパイル使用メモリ | 250,672 KB |
最終ジャッジ日時 | 2025-01-25 02:05:57 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int get(vector<int> &c){ int ret = 0; rep(i,10){ if(c[i]>0)ret |= 1<<i; } return ret; } int main(){ vector<bool> f(5000001,true); f[0] = false; f[1] = false; for(int i=2;i<f.size();i++){ if(!f[i])continue; for(int j=i*2;j<f.size();j+=i)f[j] = false; } vector<int> t(f.size(),0); rep(i,f.size()){ if(f[i]){ int x = i; while(x!=0){ t[i] |= 1<<(x%10); x/=10; } } } int N; cin>>N; int tt = 0; rep(i,N){ int x; cin>>x; tt |= 1<<x; } int ans = -1; vector<int> cnt(10,0); int l = 1; for(int i=1;i<f.size();i++){ if(f[i]){ rep(j,10){ if((t[i]>>j)&1)cnt[j]++; } } while((get(cnt)|tt)!=tt){ if(f[l]){ rep(j,10){ if((t[l]>>j)&1)cnt[j]--; } } l++; } if(get(cnt)==tt)ans = max(ans,i-l); } if(ans==0)ans = -1; cout<<ans<<endl; return 0; }