結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
atn112323
|
| 提出日時 | 2016-05-03 17:39:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,012 bytes |
| コンパイル時間 | 696 ms |
| コンパイル使用メモリ | 60,512 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-16 16:33:32 |
| 合計ジャッジ時間 | 1,643 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#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;
}
atn112323