結果

問題 No.6 使いものにならないハッシュ
ユーザー Kutimoti_TKutimoti_T
提出日時 2017-12-17 16:54:57
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,616 bytes
コンパイル時間 2,462 ms
コンパイル使用メモリ 70,952 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-10-14 23:10:34
合計ジャッジ時間 11,331 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,356 KB
testcase_02 AC 521 ms
4,388 KB
testcase_03 AC 26 ms
4,352 KB
testcase_04 AC 90 ms
4,352 KB
testcase_05 AC 59 ms
4,352 KB
testcase_06 AC 268 ms
4,356 KB
testcase_07 AC 233 ms
4,348 KB
testcase_08 AC 278 ms
4,352 KB
testcase_09 AC 491 ms
4,352 KB
testcase_10 WA -
testcase_11 AC 24 ms
4,352 KB
testcase_12 AC 250 ms
4,352 KB
testcase_13 AC 424 ms
4,348 KB
testcase_14 AC 438 ms
4,352 KB
testcase_15 AC 196 ms
4,356 KB
testcase_16 AC 403 ms
4,348 KB
testcase_17 AC 500 ms
4,372 KB
testcase_18 AC 510 ms
4,356 KB
testcase_19 AC 461 ms
4,352 KB
testcase_20 AC 318 ms
4,352 KB
testcase_21 AC 11 ms
4,348 KB
testcase_22 AC 411 ms
4,352 KB
testcase_23 AC 272 ms
4,352 KB
testcase_24 AC 357 ms
4,352 KB
testcase_25 AC 239 ms
4,352 KB
testcase_26 AC 461 ms
4,352 KB
testcase_27 AC 414 ms
4,348 KB
testcase_28 AC 130 ms
4,352 KB
testcase_29 AC 467 ms
4,348 KB
testcase_30 AC 344 ms
4,372 KB
testcase_31 AC 358 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define FOR(i, s, e) for (int i = (s); i <= (e); i++)

vector<int> prime;

int hash_[2000001];

int K;
int N;

int s = -1;
int e = -1;

int result = 0;
int cou;

int main()
{
    cin >> K;
    cin >> N;
    for (int i = 2; i <= N; i++)
    {
        bool pri = true;
        for (int j = 0; j < prime.size() && pri; j++)
        {
            if (i % prime[j] == 0)
                pri = false;
        }

        if (pri)
        {
            prime.push_back(i);
            if (i >= K && s == -1)
                s = prime.size() - 1;
            if (i <= N)
            {
                e = prime.size() - 1;
            }
        }
    }

    FOR(i, 1, N)
    {
        if (i <= 9)
            hash_[i] = i;
        else
        {
            int tot = 0;
            int x = i;
            while (x != 0)
            {
                tot += x % 10;
                x /= 10;
            }
            hash_[i] = hash_[tot];
        }
    }
    int start = e;
    bool used[10];
    fill(used, used + 10, false);
    for (int i = e; i >= s; i--)
    {
        int h = hash_[prime[i]];
        if (used[h] == false)
        {
            used[h] = true;
        }
        else
        {
            if (cou < start - i)
            {
                cou = start - i;
                result = prime[i + 1];
            }
            i = start;
            start--;
            fill(used, used + 10, false);
        }
    }
    cout << result << endl;
    return 0;
}
0