結果

問題 No.6 使いものにならないハッシュ
ユーザー けーむけーむ
提出日時 2020-05-14 11:32:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,275 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 181,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-14 23:23:57
合計ジャッジ時間 3,206 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct isPrime {
private:
    vector<bool> data;
    
public:
    isPrime() {}
    isPrime(int n) {
        data.resize(n + 1, true);
        data[0] = data[1] = false;
        for(long long i = 2; (i * i) <= n; i++) {
            if (!data[i]) continue;
            for(long long j = 2; (i * j) <= n; j++) {
                data[i * j] = false;
            }
        }
    }
    
    bool is_prime(int n) {
        return data[n];
    }
    
    vector<int> get_primes_vector() {
        vector<int> ans;
        int n = data.size();
        for(int i = 0; i < n; i++) {
            if (data[i]) ans.push_back(i);
        }
        return ans;
    }
    
    set<int> get_primes_set() {
        set<int> ans;
        int n = data.size();
        for(int i = 0; i < n; i++) {
            if (data[i]) ans.insert(i);
        }
        return ans;
    }
};

ll get_hash(ll n) {
    while(n >= 10) {
        ll tmp = 0;
        while(n > 0) {
            tmp += n % 10;
            n /= 10;
        }
        n = tmp;
    }
    return n;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll k, n;
    cin >> k >> n;
    isPrime ip(n);
    auto pv = ip.get_primes_vector();
    auto it = lower_bound(all(pv), k);
    ll l = (it - pv.begin()) - 1;
    ll r = l;
    set<ll> s;
    ll mcnt = 1, mval = pv[l];
    while(l < sz(pv)) {
        if (l >= 0) {
            s.erase(get_hash(pv[l]));
        }
        l++;
        while((r + 1) < sz(pv)) {
            ll v = get_hash(pv[r + 1]);
            if (s.count(v) > 0) break;
            s.insert(v);
            r++;
        }
        if ((r - l) >= mcnt) {
            mcnt = r - l;
            mval = pv[l];
        }
    }
    cout << mval << endl;
    return 0;
}
0