結果

問題 No.6 使いものにならないハッシュ
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2022-12-19 02:12:35
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,301 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 147,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 01:56:26
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;

vector<bool> prime;

//O(NloglogN)
void erat(long long N){
    prime.resize(N+1, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (long long i=2; i*i<=N; i++){
        if (prime[i]){
            for (long long j=i*2; j <= N; j+=i){
                prime[j] = 0;
            }
        }
    }
}

long long myhash(long long X){
    long long c=0;
    while(X != 0){
        c += X%10;
        X /= 10;
    }

    if (c >= 10) c = myhash(c);

    return c;
}

int main(){

    long long N, K, M, mx=-1, argmx, l=0, cnt=0;
    cin >> K >> N;
    erat(N);
    vector<long long> p, h;

    for (int i=K; i<=N; i++){
        if (prime[i]) p.push_back(i);
    }

    M = p.size();
    h.resize(M);

    for (int i=0; i<M; i++) h[i] = myhash(p[i]);

    map<long long, long long> mp;
    for (int r=0; r<M; r++){
        if (mp[h[r]] == 0) cnt++;
        mp[h[r]]++;
        while(l < r && mp[h[r]] > 1){
            if (mp[h[l]] == 1) cnt--;
            mp[h[l]]--;
            l++;
        }
        if (cnt >= mx){
            mx = cnt;
            argmx = l;
        }
    }

    cout << p[argmx] << endl;

    return 0;
}
0