結果

問題 No.6 使いものにならないハッシュ
ユーザー recososorecososo
提出日時 2020-05-31 13:34:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,404 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 174,336 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 16:16:29
合計ジャッジ時間 2,998 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:63:13: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   63 |     cout << ans << endl;
      |             ^~~
main.cpp:51:9: note: 'ans' was declared here
   51 |     int ans;
      |         ^~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
vector<int> mem(200001,-1);
int f(int x){
    if(mem[x]!=-1){
        return mem[x];
    }
    if(x<10){
        return mem[x]=x;
    }
    int sum=0;
    while(x){
        sum+=x%10;
        x/=10;
    }
    return mem[x]=f(sum);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k,n;cin >> k >> n;
    vector<bool> p(n+1,true);
    p[0]=p[1]=false;
    for(int i=2;i*i<=n;i++){
        if(p[i]){
            for(int j=2;j*i<=n;j++){
                p[i*j]=false;
            }
        }
    }
    vector<int> v,h;
    for(int i=k;i<=n;i++){
        if(p[i]){
            v.push_back(i);
            h.push_back(f(i));
        }
    }
    int r=0;
    int x=h.size();
    int len=0;
    int ans;
    vector<int> c(10);
    for(int i=0;i<x;i++){
        while(r<x&&!c[h[r]]){
            c[h[r]]++;
            r++;
        }
        if(chmax(len,r-i)){
            ans=v[i];
        }
        c[h[i]]--;
    }
    cout << ans << endl;
}
0