結果

問題 No.6 使いものにならないハッシュ
ユーザー xuzijian629xuzijian629
提出日時 2018-11-02 00:42:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,149 bytes
コンパイル時間 1,983 ms
コンパイル使用メモリ 209,380 KB
実行使用メモリ 5,144 KB
最終ジャッジ日時 2023-10-14 23:12:46
合計ジャッジ時間 3,291 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,444 KB
testcase_01 AC 4 ms
4,560 KB
testcase_02 AC 6 ms
5,144 KB
testcase_03 AC 5 ms
4,844 KB
testcase_04 AC 4 ms
4,764 KB
testcase_05 AC 5 ms
4,940 KB
testcase_06 AC 5 ms
4,892 KB
testcase_07 AC 5 ms
4,832 KB
testcase_08 AC 4 ms
4,804 KB
testcase_09 AC 4 ms
4,872 KB
testcase_10 AC 4 ms
4,420 KB
testcase_11 AC 4 ms
4,400 KB
testcase_12 AC 6 ms
4,932 KB
testcase_13 AC 4 ms
4,556 KB
testcase_14 AC 4 ms
4,828 KB
testcase_15 AC 6 ms
4,848 KB
testcase_16 AC 5 ms
4,796 KB
testcase_17 AC 6 ms
4,864 KB
testcase_18 AC 6 ms
5,008 KB
testcase_19 AC 5 ms
4,904 KB
testcase_20 AC 5 ms
4,888 KB
testcase_21 AC 4 ms
4,660 KB
testcase_22 AC 6 ms
4,980 KB
testcase_23 AC 6 ms
4,892 KB
testcase_24 AC 6 ms
5,088 KB
testcase_25 AC 5 ms
4,812 KB
testcase_26 AC 6 ms
4,972 KB
testcase_27 AC 5 ms
4,896 KB
testcase_28 AC 5 ms
4,828 KB
testcase_29 AC 6 ms
5,132 KB
testcase_30 AC 5 ms
4,944 KB
testcase_31 AC 6 ms
4,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:54:13: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   54 |     cout << ans << endl;
      |             ^~~
main.cpp:34:17: 備考: ‘ans’ はここで定義されています
   34 |     int sz = 0, ans;
      |                 ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int numroot(int k) {
    if (k == 0) return 0;
    if (k % 9 == 0) return 9;
    return k % 9;
}

vi ps(202020, 1);

int main() {
    ps[0] = ps[1] = 0;
    for (int i = 2; i < 202020; i++) {
        if (ps[i] == 0) continue;
        for (int j = 2; i * j < 202020; j++) {
            ps[i * j] = 0;
        }
    }

    int k, n;
    cin >> k >> n;
    vi qs;
    for (int i = k; i <= n; i++) {
        if (ps[i]) qs.push_back(i);
    }

    set<int> roots;

    int l = 0, r = 0;
    int sz = 0, ans;
    while (1) {
        if (r >= qs.size()) break; 
        int root = numroot(qs[r]);
        if (roots.count(root) == 0) {
            r++;
            roots.insert(root);
            if (roots.size() >= sz) {
                sz = roots.size();
                ans = qs[l];
            }
        } else {
            while (1) {
                int root2 = numroot(qs[l]);
                roots.erase(root2);
                l++;
                if (root == root2) break;
            }
        }
    }
    cout << ans << endl;
}
0