結果

問題 No.12 限定された素数
ユーザー 沙耶花沙耶花
提出日時 2021-10-20 21:23:16
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 6,845 ms
コンパイル使用メモリ 263,268 KB
実行使用メモリ 23,392 KB
最終ジャッジ日時 2023-10-20 11:09:45
合計ジャッジ時間 11,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 205 ms
23,392 KB
testcase_01 AC 207 ms
23,392 KB
testcase_02 AC 206 ms
23,392 KB
testcase_03 AC 129 ms
23,392 KB
testcase_04 AC 205 ms
23,392 KB
testcase_05 AC 208 ms
23,392 KB
testcase_06 AC 213 ms
23,392 KB
testcase_07 AC 217 ms
23,392 KB
testcase_08 AC 207 ms
23,392 KB
testcase_09 AC 206 ms
23,392 KB
testcase_10 AC 208 ms
23,392 KB
testcase_11 AC 219 ms
23,392 KB
testcase_12 AC 215 ms
23,392 KB
testcase_13 AC 211 ms
23,392 KB
testcase_14 AC 207 ms
23,392 KB
testcase_15 AC 211 ms
23,392 KB
testcase_16 AC 224 ms
23,392 KB
testcase_17 AC 205 ms
23,392 KB
testcase_18 AC 206 ms
23,392 KB
testcase_19 AC 204 ms
23,392 KB
testcase_20 AC 206 ms
23,392 KB
testcase_21 AC 206 ms
23,392 KB
testcase_22 AC 206 ms
23,392 KB
testcase_23 AC 205 ms
23,392 KB
testcase_24 AC 205 ms
23,392 KB
testcase_25 AC 207 ms
23,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0