結果

問題 No.6 使いものにならないハッシュ
ユーザー h_nosonh_noson
提出日時 2016-03-24 17:49:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,515 bytes
コンパイル時間 559 ms
コンパイル使用メモリ 72,152 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:58:55
合計ジャッジ時間 1,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 5 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 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,352 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,356 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 4 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 4 ms
4,352 KB
testcase_31 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:69:13: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     cout << ans << endl;
             ^~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

typedef long long ll;

int hsh(int x) {
    int tmp = 0;
    if (x < 10)
        return x;
    else {
        while (x >= 10) {
            tmp += x % 10;
            x /= 10;
        }
        return hsh(tmp + x);
    }
}

int main() {
    int i, j, k, n, index, ans, len, mlen;
    bool p[200001];
    set<int> s;
    cin >> k >> n;
    fill(p,p+200000,true);
    p[0] = p[1] = false;
    REP (i,2,1500) {
        if (p[i]) {
            for (j = 2*i; j <= 200000; j+=i)
                p[j] = false;
        }
    }
    index = k;
    while (!p[index]) index++;
    mlen = len = 0;
    REP (i,k,n+1) {
        if (p[i]) {
            int h = hsh(i);
            if (s.count(h)) {
                j = index;
                while (!p[j] || h != hsh(j)) {
                    if (p[j]) {
                        s.erase(hsh(j));
                        len--;
                    }
                    j++;
                }
                index = j+1;
                while (!p[index]) index++;
            }
            else {
                len++;
                s.insert(h);
            }
            if (len >= mlen) {
                mlen = len;
                ans = index;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0