結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-08-18 01:03:48 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 61 ms / 5,000 ms | 
| コード長 | 1,004 bytes | 
| コンパイル時間 | 2,161 ms | 
| コンパイル使用メモリ | 197,160 KB | 
| 最終ジャッジ日時 | 2025-01-30 23:41:06 | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int L,R; cin >> L >> R;
    vector<int> P, isP(R + 1, 1);
    isP[0] = isP[1] = 0;
    for(int i = 1; i <= R; i++) {
        if(isP[i]) {
            if(L <= i && i <= R) P.push_back(i);
            for(int j = i + i; j <= R; j += i) {
                isP[j] = 0;
            }
        }
    }
    int N = P.size();
    vector<int> H(N);
    rep(i,N) {
        int x = P[i];
        while(!(x < 10)) {
            string s = to_string(x);
            x = 0;
            for(char c : s) x += c - '0';
        }
        H[i] = x;
    }
    int ans = 0, fir = -1;
    vector<int> cnt(10, 0);
    for(L = 0, R = 0; L < N; L++) {
        while(R < N && cnt[H[R]] == 0) cnt[H[R]]++, R++;
        if(ans <= R - L) {
            ans = R - L;
            fir = P[L];
        }
        cnt[H[L]]--;
    }
    cout << fir << endl;
}
            
            
            
        