結果

問題 No.12 限定された素数
ユーザー TwizzTwizz
提出日時 2017-05-20 00:47:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,122 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 168,272 KB
実行使用メモリ 10,200 KB
最終ジャッジ日時 2023-10-19 02:53:48
合計ジャッジ時間 4,454 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
10,196 KB
testcase_01 AC 66 ms
10,200 KB
testcase_02 AC 61 ms
10,196 KB
testcase_03 WA -
testcase_04 AC 61 ms
10,196 KB
testcase_05 AC 66 ms
10,200 KB
testcase_06 AC 67 ms
10,200 KB
testcase_07 AC 69 ms
10,200 KB
testcase_08 AC 64 ms
10,200 KB
testcase_09 AC 62 ms
10,200 KB
testcase_10 AC 64 ms
10,200 KB
testcase_11 AC 74 ms
10,200 KB
testcase_12 AC 71 ms
10,200 KB
testcase_13 AC 68 ms
10,200 KB
testcase_14 AC 68 ms
10,200 KB
testcase_15 AC 67 ms
10,200 KB
testcase_16 AC 75 ms
10,200 KB
testcase_17 AC 65 ms
10,196 KB
testcase_18 AC 61 ms
10,196 KB
testcase_19 AC 61 ms
10,196 KB
testcase_20 AC 61 ms
10,200 KB
testcase_21 AC 62 ms
10,200 KB
testcase_22 AC 61 ms
10,196 KB
testcase_23 AC 61 ms
10,196 KB
testcase_24 AC 65 ms
10,196 KB
testcase_25 AC 64 ms
10,200 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);
		}
	}
	print(ans);
	return 0;
}
0