結果

問題 No.6 使いものにならないハッシュ
ユーザー atn112323atn112323
提出日時 2016-05-03 17:39:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,012 bytes
コンパイル時間 392 ms
コンパイル使用メモリ 61,284 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-14 22:59:24
合計ジャッジ時間 1,567 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,352 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 3 ms
4,356 KB
testcase_18 AC 4 ms
4,352 KB
testcase_19 AC 3 ms
4,352 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 3 ms
4,352 KB
testcase_23 AC 3 ms
4,352 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,352 KB
testcase_28 AC 3 ms
4,372 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,352 KB
testcase_31 AC 3 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

int K, N;
bool is_prime[200001];

int main() {
	cin >> K >> N;
	for (int i = 0; i <= 200000; i++) {
		is_prime[i] = true;
	}
	is_prime[0] = false;
	is_prime[1] = false;
	for (int d = 2; d * d <= 200000; d++) {
		if (is_prime[d]) {
			for (int dd = d + d; dd <= 200000; dd += d) {
				is_prime[dd] = false;
			}
		}
	}
	vector<int> primes;
	vector<int> hashes;
	for (int i = K; i <= N; i++) {
		if (is_prime[i]) {
			primes.push_back(i);
			int n = i;
			while (n >= 10) {
				int nn = n;
				n = 0;
				while (nn > 0) {
					n += nn % 10;
					nn /= 10;
				}
			}
			hashes.push_back(n);
		}
	}
	int cnt[10];
	for (int i = 0; i < 10; i++) {
		cnt[i] = 0;
	}
	int res = -1;
	int best = 0;
	int s = 0, t = 0;
	while (s < primes.size()) {
		while (t < primes.size() && cnt[hashes[t]] == 0) {
			cnt[hashes[t]]++;
			t++;
		}
		if (t - s >= best) {
			res = primes[s];
			best = t - s;
		}
		cnt[hashes[s]]--;
		s++;
	}
	cout << res << endl;
	return 0;
}
0