結果

問題 No.6 使いものにならないハッシュ
ユーザー goodbatongoodbaton
提出日時 2014-11-23 17:02:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 1,476 bytes
コンパイル時間 522 ms
コンパイル使用メモリ 67,716 KB
実行使用メモリ 4,476 KB
最終ジャッジ日時 2023-10-14 22:47:28
合計ジャッジ時間 2,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 10 ms
4,356 KB
testcase_03 AC 4 ms
4,372 KB
testcase_04 AC 4 ms
4,352 KB
testcase_05 AC 5 ms
4,368 KB
testcase_06 AC 6 ms
4,352 KB
testcase_07 AC 5 ms
4,352 KB
testcase_08 AC 5 ms
4,352 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 AC 7 ms
4,372 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 4 ms
4,364 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 5 ms
4,372 KB
testcase_17 AC 7 ms
4,348 KB
testcase_18 AC 9 ms
4,352 KB
testcase_19 AC 7 ms
4,352 KB
testcase_20 AC 7 ms
4,348 KB
testcase_21 AC 3 ms
4,356 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 7 ms
4,476 KB
testcase_24 AC 7 ms
4,372 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 5 ms
4,352 KB
testcase_29 AC 8 ms
4,348 KB
testcase_30 AC 8 ms
4,476 KB
testcase_31 AC 7 ms
4,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

bool so[200010];
int syaku[2][100000];

void sosu(){
    so[0]=so[1]=true;
    for(int i=2;i<=200000;i++){
        if(!so[i])
            for(int j=2;j*i<=200000;j++){
                so[j*i]=true;
            }
    }
}

int Hash(int num){
    int re=0,p,k=log10(num);
    for(int i=k;i>=0;i--){
        p = pow(10,i);
        re+=num/p;
        num=num%p;
    }
    if(re>=10)
        return Hash(re);
    else
        return re;
}

int main(){
    int k,n,j,l=0,r=0,ch[10]={0},max_lr=-1,max_s=0;
    sosu();
    
    scanf("%d%d",&k,&n);
    
    j=0;
    for(int i=k;i<=n;i++){
        if(!so[i]){
            syaku[0][j]=Hash(i);
            syaku[1][j]=i;
            j++;
        }
    }
    
    //shakutori
    while(r<=j){
        if(max_lr<=r-l){
            max_lr=r-l;
            max_s=syaku[1][l];
        }
        
        for(int i=l;i<=r;i++){
            if(ch[syaku[0][i]]){
                l++;
                break;
            }
            ch[syaku[0][i]]=1;
            if(i==r){
                r++;
                break;
            }
        }
        for(int i=0;i<10;i++){
            ch[i]=0;
        }
        
    }
    
    printf("%d\n",max_s);
    
    
    return 0;
}
0