結果

問題 No.12 限定された素数
ユーザー sigma425sigma425
提出日時 2015-09-26 18:17:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 1,261 ms
コンパイル使用メモリ 148,332 KB
実行使用メモリ 28,912 KB
最終ジャッジ日時 2023-08-15 23:07:44
合計ジャッジ時間 4,895 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
28,596 KB
testcase_01 AC 94 ms
28,912 KB
testcase_02 AC 97 ms
28,524 KB
testcase_03 AC 92 ms
28,732 KB
testcase_04 AC 97 ms
28,660 KB
testcase_05 AC 91 ms
28,744 KB
testcase_06 AC 92 ms
28,468 KB
testcase_07 AC 95 ms
28,528 KB
testcase_08 AC 92 ms
28,676 KB
testcase_09 AC 94 ms
28,472 KB
testcase_10 AC 92 ms
28,468 KB
testcase_11 AC 94 ms
28,728 KB
testcase_12 AC 93 ms
28,732 KB
testcase_13 AC 91 ms
28,676 KB
testcase_14 AC 92 ms
28,732 KB
testcase_15 AC 91 ms
28,524 KB
testcase_16 AC 93 ms
28,680 KB
testcase_17 AC 99 ms
28,912 KB
testcase_18 AC 99 ms
28,656 KB
testcase_19 AC 99 ms
28,472 KB
testcase_20 AC 97 ms
28,472 KB
testcase_21 AC 95 ms
28,600 KB
testcase_22 AC 99 ms
28,732 KB
testcase_23 AC 97 ms
28,712 KB
testcase_24 AC 98 ms
28,464 KB
testcase_25 AC 92 ms
28,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
const int MX=5000000;
bool isp[MX+1];
vector<int> ps;
vector<int> ds[10];
int main(){
	for(int i=2;i<=MX;i++) isp[i]=1;
	for(int i=2;i<=MX;i++){
		if(isp[i]){
			ps.pb(i);
			for(int j=2*i;j<=MX;j+=i) isp[j]=0;
		}
	}
	for(int p:ps){
		int tmp=p;
		int c[10]={};
		while(tmp){
			c[tmp%10]++;
			tmp/=10;
		}
		rep(i,10) ds[i].pb(c[i]);
	}
	int K;
	cin>>K;
	bool is[10]={};
	rep(i,K){
		int x;
		cin>>x;
		is[x]=1;
	}
	int ans=-1;
	int N=ps.size();
	ps.pb(MX+1);
	int j=0;
	int c[10]={};
	rep(i,N){
		chmax(j,i);
		while(j<N){
			// add j
			int nc[10];
			rep(k,10) nc[k]=c[k]+ds[k][j];
			bool ok=1;
			rep(k,10){
				if(!is[k]&&nc[k]>0) ok=0;
			}
			if(!ok) break;
			rep(k,10) c[k]=nc[k];
			j++;
		}
		bool ok=1;
		rep(k,10) if(is[k]&&c[k]==0) ok=0;
		if(ok){
			int len=ps[j]-(i==0?0:ps[i-1])-2;
			chmax(ans,len);
		}
		if(i<j){
			rep(k,10) c[k]-=ds[k][i];
		}
	}
	cout<<ans<<endl;
}
0