結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
moti
|
| 提出日時 | 2015-08-01 20:48:35 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,569 bytes |
| コンパイル時間 | 864 ms |
| コンパイル使用メモリ | 98,900 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-18 00:41:53 |
| 合計ジャッジ時間 | 1,989 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 31 WA * 1 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
//#define int ll
using namespace std;
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
bool pr[200001];
int PSIZE;
int vpr[200001];
int phash[200001];
int memo[200001];
int get_hash(int x) {
if(memo[x] > 0) { return memo[x]; }
if(x < 10) { return x; }
string s = to_string(x);
int sum = 0;
int size = s.size();
rep(i, size) {
sum += s[i]-'0';
}
return memo[x] = get_hash(sum);
}
signed main() {
int K, N; cin >> K >> N;
fill(pr, pr+200001, 1);
pr[0] = pr[1] = 0;
for(int i=2; (ll)i*i <= N+1; i++) {
if(pr[i]) {
for(ll j=i*i; j<=N+1; j+=i) {
pr[j] = 0;
}
}
}
for(int i=K; i<=N+1; i++) {
if(pr[i]) vpr[PSIZE++] = i;
}
rep(i, PSIZE) {
phash[i] = get_hash(vpr[i]);
}
int maxlen = 0, ans = 0;
int l = 0, r = 0;
unordered_set<int> st;
while(1) {
if(r >= PSIZE) { break; }
if(!st.count(phash[r])) {
st.insert(phash[r]);
if(maxlen <= (int)st.size()) {
maxlen = st.size();
ans = vpr[l];
}
r++;
}
else {
while(1) {
st.erase(phash[l++]);
if(l == r) { break; }
if(!st.count(phash[r])) {
break;
}
}
}
}
cout << ans << endl;
return 0;
}
moti