結果

問題 No.6 使いものにならないハッシュ
ユーザー uenokuuenoku
提出日時 2017-01-08 22:53:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,712 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 85,476 KB
実行使用メモリ 6,228 KB
最終ジャッジ日時 2023-10-14 23:04:02
合計ジャッジ時間 2,151 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,456 KB
testcase_01 AC 3 ms
5,356 KB
testcase_02 AC 9 ms
6,228 KB
testcase_03 AC 3 ms
5,456 KB
testcase_04 AC 5 ms
5,500 KB
testcase_05 AC 4 ms
5,572 KB
testcase_06 AC 6 ms
5,784 KB
testcase_07 AC 4 ms
5,624 KB
testcase_08 AC 5 ms
5,760 KB
testcase_09 AC 4 ms
5,436 KB
testcase_10 AC 3 ms
5,316 KB
testcase_11 AC 4 ms
5,484 KB
testcase_12 AC 6 ms
5,924 KB
testcase_13 AC 3 ms
5,660 KB
testcase_14 AC 4 ms
5,520 KB
testcase_15 AC 6 ms
5,776 KB
testcase_16 AC 5 ms
5,572 KB
testcase_17 AC 6 ms
5,940 KB
testcase_18 AC 8 ms
6,188 KB
testcase_19 AC 6 ms
5,996 KB
testcase_20 AC 6 ms
5,880 KB
testcase_21 AC 3 ms
5,472 KB
testcase_22 AC 6 ms
5,896 KB
testcase_23 AC 6 ms
5,944 KB
testcase_24 AC 6 ms
6,052 KB
testcase_25 AC 5 ms
5,596 KB
testcase_26 AC 7 ms
6,024 KB
testcase_27 AC 6 ms
5,828 KB
testcase_28 AC 5 ms
5,708 KB
testcase_29 AC 7 ms
6,124 KB
testcase_30 AC 7 ms
5,988 KB
testcase_31 AC 6 ms
5,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
vector<int> prime(int n, int k)
{
    bool isprime[2000005] = {};
    vector<int> primes;
    for (int i = 2; i <= n; i++) {
        if (!isprime[i]) {
            if (i >= k)
                primes.push_back(i);
            for (int j = 2 * i; j <= n; j += i) {
                isprime[j] = true;
            }
        }
    }
    return primes;
}
int memo[200005] = {};
int h(int g)
{
    int t = g;
    if (memo[g])
        return memo[g];
    int sum = 0;
    while (g > 0) {
        sum += g % 10;
        g /= 10;
    }
    if (sum < 10)
        return memo[t] = sum;
    else
        return memo[t] = h(sum);
}
int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> p = prime(n, k);
    int ans = 0;
    int aa = 0;
    for (int i = 0; i < p.size(); i++) {
        set<int> u;
        for (int j = i; j < p.size(); j++) {
            //cout << p[j] << '(' << h(p[j]) << ' ';
            if (u.find(h(p[j])) != u.end()) {
                if (ans <= j - i - 1) {
                    ans = max(ans, j - i - 1);
                    aa = p[i];
                }
                break;
            } else {
                u.insert(h(p[j]));
            }
            if (j == (int)p.size() - 1) {
                if (ans <= j - i) {
                    ans = max(ans, j - i);
                    aa = p[i];
                }
            }
        }
        //    cout << endl;
    }
    cout << aa << endl;
}
0