結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
Naoyk1212
|
| 提出日時 | 2017-06-09 15:25:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 1,503 bytes |
| コンパイル時間 | 788 ms |
| コンパイル使用メモリ | 96,064 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-16 16:39:33 |
| 合計ジャッジ時間 | 1,682 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;
vector<int> primes;
void sieve(int n) {
bool isPrime[200010];
for (int i = 0; i < 200010; i++)isPrime[i] = true;
isPrime[0] = false;
isPrime[1] = false;
for (int i = 0; i <= n; i++) {
if (isPrime[i] == true) {
primes.push_back(i);
for (int j = i * 2; j <= n; j += i) {
isPrime[j] = false;
}
}
}
}
int FrankHash(int n) {
int tmp = 0;
while (n > 0) {
tmp += n % 10;
n /= 10;
if (tmp >= 10) {
tmp = tmp % 10 + tmp / 10;
}
}
return tmp;
}
int main() {
int k, n;
cin >> k >> n;
sieve(n);
vector<int> v;
vector<int> hashed;
for (int i = 0; i < primes.size(); i++) {
if (primes[i] >= k && primes[i] <= n)v.push_back(primes[i]);
}
for (int i = 0; i < v.size(); i++) {
hashed.push_back(FrankHash(v[i]));
}
map<int, bool> mp;
for (int i = 1; i < 10; i++) {
mp[i] = false;
}
int s = 0;
int t = 0;
int mx = 0;
int mx_len = 0;
while (1) {
while (t < v.size() && !mp[hashed[t]]) {
mp[hashed[t++]] = true;
//cerr << v[s] << " " << v[t] << endl;
}
if (v.size() - s < mx_len)break;
if (mx_len < t - s) {
mx_len = t - s;
mx = v[s];
}
else if (mx_len == t - s) {
mx = max(mx, v[s]);
}
mp[hashed[s++]] = false;
//cerr << mx << " " << mx_len << endl;
}
cout << mx << endl;
}
Naoyk1212