結果

問題 No.6 使いものにならないハッシュ
ユーザー recososorecososo
提出日時 2020-05-31 13:37:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,419 bytes
コンパイル時間 1,586 ms
コンパイル使用メモリ 170,524 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:24:24
合計ジャッジ時間 2,957 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 5 ms
4,352 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 4 ms
4,348 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 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,352 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 4 ms
4,352 KB
testcase_18 AC 4 ms
4,352 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 4 ms
4,352 KB
testcase_23 AC 4 ms
4,352 KB
testcase_24 AC 4 ms
4,352 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 4 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 5 ms
4,348 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:64:13: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   64 |     cout << ans << endl;
      |             ^~~
main.cpp:51:9: 備考: ‘ans’ はここで定義されています
   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(len<=r-i){
            ans=v[i];
            len=r-i;
        }
        c[h[i]]--;
    }
    cout << ans << endl;
}
0