結果

問題 No.6 使いものにならないハッシュ
ユーザー pessimist
提出日時 2025-03-08 20:25:35
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 779 bytes
コンパイル時間 6,956 ms
コンパイル使用メモリ 257,308 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2025-03-08 20:25:48
合計ジャッジ時間 8,557 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2E5+10;
bool is_prime[N];
int hsh[N];
int32_t main() {
    cin.tie(nullptr)->ios::sync_with_stdio(false);
    int L,R;cin>>L>>R;
    fill(is_prime+2,is_prime+R+1,true);
    vector<int> P;
    for(ll i=2;i<=R;i++){
        if(is_prime[i]){
            if(i>=L) hsh[P.size()]=1+(i-1)%9,P.emplace_back(i);
            for(ll j=i*i;j<=R;j+=i){
                is_prime[j]=false;
            }
        }
    }

    const int N=P.size();

    int ans=0,fir=-1;
    vector<int>cnt(10);
    for(int L=0,R=0;L<N;++L){
        while(R<N&&cnt[hsh[R]]==0)++cnt[hsh[R++]];
        if(ans<=R-L){
            ans=R-L;
            fir=P[L];
        }
        cnt[hsh[L]]--;
    }
    cout<<fir<<endl;
    return 0;
} 
0