結果

問題 No.6 使いものにならないハッシュ
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-29 19:24:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,665 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 169,880 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 23:18:08
合計ジャッジ時間 2,734 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
4,356 KB
testcase_19 AC 4 ms
4,352 KB
testcase_20 AC 3 ms
4,352 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,352 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 4 ms
4,352 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,352 KB
testcase_29 AC 3 ms
4,352 KB
testcase_30 AC 3 ms
4,372 KB
testcase_31 AC 3 ms
4,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:67:13: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   67 |     cout << ans << endl;
      |             ^~~
main.cpp:52:9: 備考: ‘ans’ はここで定義されています
   52 |     int ans;
      |         ^~~

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int myhash(int n) {
    if (n <= 9) return n;
    int k = 0;
    while (n > 0) {
        k += n % 10;
        n /= 10;
    }
    return myhash(k);
}

int main() {
    int k,N; cin >> k >> N;
    // エラトステネスの篩
    // N以下の素数   
    vector<bool> isprime(N + 1, true);
    vector<int> prime;
    isprime[0] = isprime[1] = false;
    for (int i = 2; i*i <= N; i++)
    {
        if (isprime[i]) {
            for (int j = i + i; j <= N; j += i)
            {
                isprime[j] = false;
            }
        }
    }
    for (int i = k; i <= N; i++)
    {
        if (isprime[i]) {
            prime.push_back(i);
        }
    }
    vector<int> value(prime.size());
    REP(i, prime.size()) {
        value[i] = myhash(prime[i]);
    }
    int l = 0, r = 0;
    bool f[10];
    int m = 0;
    int ans;
    REP(i, 10) f[i] = false;
    while(r < value.size()) {
        while (r < value.size() && !f[value[r]]) {
            f[value[r++]] = true;
        }
        if (m <= r - l) {
            m = r - l;
            ans = prime[l];
        }
        while (r < value.size() && l < r) {
            f[value[l++]] = false;
            if (value[r] == value[l - 1]) break;
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}
0