結果

問題 No.6 使いものにならないハッシュ
ユーザー んんんんんん
提出日時 2022-12-31 16:11:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,023 bytes
コンパイル時間 2,208 ms
コンパイル使用メモリ 208,836 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 16:18:33
合計ジャッジ時間 3,861 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int M = 200000;

int myhash(int a) {
    if (a < 10) return a;
    int ret = 0;
    while (a) {
        ret += a % 10;
        a /= 10;
    }
    return myhash(ret);
}

int main() {
    vector<bool> isP(M, true);
    isP[0] = isP[1] = false;
    for (int i = 2; i <= M; i++) {
        if (isP[i]) {
            for (int j = 2*i; j <= M; j += i) {
                isP[j] = false;
            }
        }
    }

    int K, N;
    cin >> K >> N;
    vector<int> ps;
    for (int i = K; i <= N; i++) if (isP[i]) ps.push_back(i);
    set<int> st;
    int ri = 0;
    int id = -1;
    int M_len = -1;
    for (int le = 0; le < ps.size(); le++) {
        while (ri < ps.size() && st.count(myhash(ps[ri])) == 0) {
            st.insert(myhash(ps[ri]));
            ri++;
        }

        if (M_len <= ri - le) {
            M_len = ri - le;
            id = le;
        }

        if (ri == le) ri++;
        else st.erase(myhash(ps[le]));
    }

    cout << ps[id] << endl;
}
0