結果

問題 No.6 使いものにならないハッシュ
ユーザー OmameBeansOmameBeans
提出日時 2021-07-06 18:03:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,030 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 175,240 KB
実行使用メモリ 16,112 KB
最終ジャッジ日時 2023-09-14 04:25:38
合計ジャッジ時間 4,927 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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])) {
                if(chmax(m,r-l)) ans = A[l];
                break;
            }
            st.insert(B[r]);
            //cout << A[r] << "," << B[r] << " ";
        }
        //cout << endl;
    }

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