結果

問題 No.6 使いものにならないハッシュ
ユーザー yogi_cgyogi_cg
提出日時 2020-03-27 20:23:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,690 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 171,560 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-14 23:22:43
合計ジャッジ時間 2,865 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 5 ms
4,348 KB
testcase_03 AC 3 ms
4,356 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 3 ms
4,348 KB
testcase_09 AC 3 ms
4,352 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 4 ms
4,352 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,356 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 4 ms
4,352 KB
testcase_18 AC 5 ms
4,368 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 4 ms
4,352 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 4 ms
4,352 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 3 ms
4,352 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 4 ms
4,352 KB
testcase_30 AC 4 ms
4,352 KB
testcase_31 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e10;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int h(int n)
{
    int res = 0;
    while(n > 0)
    {
        res += n % 10;
        n /= 10;
    }
    if(res >= 10) return h(res);
    return res;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int K, N; cin >> K >> N;
    vb isPrime(200001, true); isPrime[0] = isPrime[1] = false;
    for(int i = 2; i <= 200000; i++)
    {
        if(isPrime[i])
        {
            for(int j = 2*i; j <= 200000; j += i) isPrime[j] = false;
        }
    }

    vpi table;
    for(int i = K; i <= N; i++)
    {
        if(isPrime[i]) table.push_back(make_pair(i, h(i)));
    }

    vb v(10, false);
    int r = 0, x = table[0].first;
    int len = 0;
    for(int l = 0; l < table.size(); l++)
    {
        while(r < table.size() && !v[table[r].second])
        {
            v[table[r].second] = true;
            r++;
        }
        if(len <= r-l)
        {
            len = r-l;
            x = table[l].first;
        }
        v[table[l].second] = false;
    }
    cout << x << endl;
}
0