結果

問題 No.6 使いものにならないハッシュ
コンテスト
ユーザー 👑 ONPU3
提出日時 2026-10-14 23:16:19
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 5,000 ms
+ 481µs
コード長 1,063 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,375 ms
コンパイル使用メモリ 345,164 KB
実行使用メモリ 9,872 KB
最終ジャッジ日時 2026-10-14 23:16:27
合計ジャッジ時間 4,660 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<bool>is(200009,true);
    is[0]=is[1]=false;
    for(ll i=2;i<200009;i++)
    {
        if(!is[i])continue;
        for(ll j=i+i;j<200009;j+=i)is[j]=false;
    }
    int k,n;cin>>k>>n;
    vector<pair<ll,ll>>p;
    for(int i=k;i<=n;i++)
    {
        if(!is[i])continue;
        ll now=i;
        while(now>=10)
        {
            ll nex=0,j=now;
            while(j)
            {
                nex+=j%10;
                j/=10;
            }
            now=nex;
        }
        p.push_back({i,now});
    }
    set<ll>st;
    ll ans=0,mx=0,r=0,m=p.size();
    for(int i=0;i<m;i++)
    {
        while(r<m&&!st.contains(p[r].second))
        {
            st.insert(p[r].second);
            r++;
        }
        if(r-i>mx)
        {
            mx=r-i;
            ans=max(ans,p[i].first);
        }
        else if(r-i==mx)ans=max(ans,p[i].first);
        st.erase(p[i].second);
    }
    cout<<ans<<endl;
}
0