結果

問題 No.12 限定された素数
ユーザー ttkkggwwttkkggww
提出日時 2022-03-08 23:22:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 251 ms / 5,000 ms
コード長 1,155 bytes
コンパイル時間 5,263 ms
コンパイル使用メモリ 262,484 KB
実行使用メモリ 103,708 KB
最終ジャッジ日時 2023-10-01 05:57:28
合計ジャッジ時間 12,745 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 251 ms
103,644 KB
testcase_01 AC 242 ms
102,092 KB
testcase_02 AC 245 ms
102,888 KB
testcase_03 AC 244 ms
102,504 KB
testcase_04 AC 243 ms
102,676 KB
testcase_05 AC 240 ms
102,640 KB
testcase_06 AC 237 ms
102,676 KB
testcase_07 AC 240 ms
103,140 KB
testcase_08 AC 245 ms
103,708 KB
testcase_09 AC 245 ms
102,632 KB
testcase_10 AC 242 ms
102,232 KB
testcase_11 AC 238 ms
102,724 KB
testcase_12 AC 244 ms
102,848 KB
testcase_13 AC 246 ms
102,092 KB
testcase_14 AC 242 ms
101,992 KB
testcase_15 AC 246 ms
102,616 KB
testcase_16 AC 243 ms
102,928 KB
testcase_17 AC 243 ms
102,636 KB
testcase_18 AC 243 ms
103,612 KB
testcase_19 AC 245 ms
103,528 KB
testcase_20 AC 239 ms
103,300 KB
testcase_21 AC 239 ms
102,460 KB
testcase_22 AC 233 ms
102,752 KB
testcase_23 AC 236 ms
102,684 KB
testcase_24 AC 243 ms
102,620 KB
testcase_25 AC 239 ms
102,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
ll n;
vector<int> a;

vector<long long> primes(long long n){
	vector<long long> res;
	vector<long long> is(n);
	is[0] = 1;
	is[1] = 1;
	for(int i = 2;i<n;i++){
		if(is[i]==0){
			for(int j = i*2;j<n;j+=i){
				is[j] = 1;
			}
		}
	}
	for(int i = 2;i<n;i++){
		if(is[i]==0){
			res.push_back(i);
		}
	}
	return is;
}

int f(int x){
	int res = 0;
	while(x){
		int y = x%10;
		x/=10;
		res |= (1<<y);
	}
	return res;
}

void solve(){
	auto v = primes(5000001);
	vector<int> fv;
	for(int i = 0;i<5000001;i++){
		if(v[i]==0){
			fv.push_back(f(i));
		}else{
			fv.push_back(0);
		}
	}
	int y = 0;
	for(int i = 0;i<n;i++)y |= 1<<a[i];
	int l = 0;
	int x = 0;
	int ans = -1;
	v.push_back(0);
	fv.push_back(1<<12);
	for(int i = 1;i<=5000001;i++){
		if((~y)&fv[i]){
			if(x==y){
				if(ans<l){
				}
				ans = max(l,ans);
			}
			x = 0;
			l = 0;
		}else{
			x |= fv[i];
			l++;
		}
	}
	cout<<max(-1,ans-1)<<endl;
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	a = vector<int>(n);
	for(auto &i:a)cin >> i;
	solve();
}
0