結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-06 23:54:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 722 bytes |
| コンパイル時間 | 3,430 ms |
| コンパイル使用メモリ | 283,300 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-08-06 23:54:35 |
| 合計ジャッジ時間 | 5,047 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int K,N;cin>>K>>N;
vector<bool> is_prime(N+1,true);
vector<int> primes;
for(int i=2;i<=N;i++){
if(!is_prime[i]) continue;
if(K<=i) primes.push_back(i);
for(int j=2*i;j<=N;j+=i) is_prime[j]=false;
}
auto mhash=[](auto &&mhash,int n)->int{
if(0<=n and n<9) return n;
int t=0;
while(n){t+=n%10;n/=10;}
return mhash(mhash,t);
};
queue<int> que;
int mlen=0,ans=0;
vector<bool> v(10,false);
for(auto p:primes){
int t=mhash(mhash,p);
while(v[t]){
v[mhash(mhash,que.front())]=false;
que.pop();
}
que.push(p);
v[t]=true;
if(mlen<=(int)que.size()){
mlen=que.size();
ans=que.front();
}
}
cout<<ans<<"\n";
return 0;
}