結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-05-31 13:34:27 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,404 bytes | 
| コンパイル時間 | 1,769 ms | 
| コンパイル使用メモリ | 172,736 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2024-11-17 09:48:15 | 
| 合計ジャッジ時間 | 2,997 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 3 WA * 29 | 
コンパイルメッセージ
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;
      |         ^~~
            
            ソースコード
#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;
}
            
            
            
        