結果

問題 No.6 使いものにならないハッシュ
ユーザー OmameBeansOmameBeans
提出日時 2021-07-06 18:05:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 2,023 bytes
コンパイル時間 2,847 ms
コンパイル使用メモリ 175,404 KB
実行使用メモリ 16,016 KB
最終ジャッジ日時 2023-09-14 04:26:01
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
15,624 KB
testcase_01 AC 25 ms
15,708 KB
testcase_02 AC 28 ms
15,892 KB
testcase_03 AC 24 ms
15,712 KB
testcase_04 AC 24 ms
15,648 KB
testcase_05 AC 24 ms
15,640 KB
testcase_06 AC 25 ms
15,752 KB
testcase_07 AC 24 ms
15,584 KB
testcase_08 AC 25 ms
15,552 KB
testcase_09 AC 23 ms
15,636 KB
testcase_10 AC 23 ms
15,872 KB
testcase_11 AC 24 ms
15,644 KB
testcase_12 AC 26 ms
15,808 KB
testcase_13 AC 23 ms
15,712 KB
testcase_14 AC 23 ms
15,796 KB
testcase_15 AC 26 ms
15,864 KB
testcase_16 AC 23 ms
15,652 KB
testcase_17 AC 26 ms
15,716 KB
testcase_18 AC 28 ms
16,016 KB
testcase_19 AC 26 ms
15,792 KB
testcase_20 AC 25 ms
15,736 KB
testcase_21 AC 24 ms
15,620 KB
testcase_22 AC 26 ms
15,740 KB
testcase_23 AC 27 ms
15,868 KB
testcase_24 AC 27 ms
15,848 KB
testcase_25 AC 26 ms
15,708 KB
testcase_26 AC 27 ms
15,872 KB
testcase_27 AC 26 ms
15,872 KB
testcase_28 AC 24 ms
15,596 KB
testcase_29 AC 28 ms
15,736 KB
testcase_30 AC 28 ms
15,812 KB
testcase_31 AC 27 ms
15,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define DREP(i,s,n) for(int i = (s); i < (n); i++)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a <= b) {a = b;return true;}return false;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

int disit_sum(int N) {
    int ans = 0;
    while(N) {
        ans += N%10;
        N /= 10;
    }
    return ans;
}

void cal(int i, vecveci &G, veci &dp) {
    if(dp[i] != -1) return;
    for(int ni : G[i]) {
        cal(ni,G,dp);
        dp[i] = dp[ni];
    }
}

int main() {
    int K,N; cin >> K >> N;
    veci prime(200010);
    for(int i = 1; i < 200010; i++) {
        for(int j = i; j < 200010; j += i) {
            prime[j]++;
        }
    }
    vecveci G(200010);
    veci dp(200010,-1);

    for(int i = 0; i < 200010; i++) {
        if(i >= 10) G[i].push_back(disit_sum(i));
        else dp[i] = i;
    }

    int cnt = 0;
    veci A,B;

    for(int i = K; i <= N; i++) {
        if(i == 1) continue;
        if(prime[i] > 2) continue;
        cnt++;
        cal(i,G,dp);
        A.push_back(i);
        B.push_back(dp[i]);
    }

    int M = A.size();

    int ans = 1e9;
    int m = 0;

    for(int l = 0; l < M; l++) {
        set<int> st;
        bool ok = true;
        int r;
        for(r = l; r < M; r++) {
            if(st.count(B[r])) {
                break;
            }
            st.insert(B[r]);
            //cout << A[r] << "," << B[r] << " ";
        }
        if(chmax(m,r-l)) ans = A[l];
        //cout << endl;
    }

    cout << ans << endl;
    
    return 0;
}
0