結果

問題 No.12 限定された素数
ユーザー TwizzTwizz
提出日時 2017-05-20 00:50:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 1,158 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 152,628 KB
実行使用メモリ 10,324 KB
最終ジャッジ日時 2023-08-16 00:41:55
合計ジャッジ時間 4,609 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
9,960 KB
testcase_01 AC 87 ms
10,104 KB
testcase_02 AC 80 ms
10,092 KB
testcase_03 AC 104 ms
10,140 KB
testcase_04 AC 79 ms
10,144 KB
testcase_05 AC 87 ms
10,008 KB
testcase_06 AC 87 ms
10,012 KB
testcase_07 AC 90 ms
10,148 KB
testcase_08 AC 81 ms
10,004 KB
testcase_09 AC 85 ms
9,944 KB
testcase_10 AC 86 ms
10,304 KB
testcase_11 AC 96 ms
10,024 KB
testcase_12 AC 92 ms
10,100 KB
testcase_13 AC 95 ms
10,120 KB
testcase_14 AC 92 ms
10,324 KB
testcase_15 AC 93 ms
10,136 KB
testcase_16 AC 94 ms
9,936 KB
testcase_17 AC 85 ms
10,056 KB
testcase_18 AC 80 ms
9,956 KB
testcase_19 AC 81 ms
10,060 KB
testcase_20 AC 81 ms
10,008 KB
testcase_21 AC 82 ms
10,268 KB
testcase_22 AC 82 ms
10,008 KB
testcase_23 AC 82 ms
10,136 KB
testcase_24 AC 87 ms
10,096 KB
testcase_25 AC 87 ms
9,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"

//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
typedef long long ll;
const ll mod = 10000000000;

int n;
set<int>a;
int cnt[10] = {};
int MAX = 5000000;

bool dp[5000000];

bool hantei() {
	REP(i, 10) {
		if (a.count(i) == 0) {
			if (cnt[i] != 0)return false;
		}
	}
	return true;
}

bool ok() {
	REP(i, 10) {
		if (a.count(i) != 0) {
			if (cnt[i] == 0)return false;
		}
	}
	return true;
}

vector<int> prime() {
	vector<int> ret;
	for (int i = 2; i < MAX; i++)
	{
		if (dp[i]) continue;
		ret.push_back(i);
		for (int j = i + i; j < MAX; j += i)
		{
			dp[j] = true;
		}
	}
	return ret;
}

int main() {
	cin >> n;
	REP(i, n) {
		int t; cin >> t;
		a.insert(t);
	}

	vector<int>v = prime();
	REP(i, 10)cnt[i] = 0;
	int ans = -1;
	int l = 1;
	REP(i, v.size()) {
		string tm = to_string(v[i]);
		REP(j, tm.size()) {
			cnt[tm[j] - '0']++;
		}
		if (!hantei()) {
			REP(j, 10)cnt[j] = 0;
			l = v[i] + 1;
		}
		if (ok()) {
			ans = max(ans, v[i+1]-1 - l);
		}
		if (a.size() == 10)ans = 4999999;
	}
	print(ans);
	return 0;
}
0