結果

問題 No.6 使いものにならないハッシュ
ユーザー Humpty0904Humpty0904
提出日時 2016-06-15 04:53:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 760 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 46,916 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:59:34
合計ジャッジ時間 1,743 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 4 ms
4,352 KB
testcase_06 AC 4 ms
4,352 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 4 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 4 ms
4,352 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 4 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 5 ms
4,348 KB
testcase_19 AC 5 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,348 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 3 ms
4,352 KB
testcase_26 AC 4 ms
4,352 KB
testcase_27 AC 4 ms
4,352 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,352 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:38:8: warning: ‘result_val’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  printf("%d\n",result_val);
  ~~~~~~^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
#define M 200000
using namespace std;

int _hash(int n){
	for(;n>9;){
		int s=0;
		for(;n;n/=10)s+=n%10;
		n=s;
	}
	return n;
}
int table[M+1],p[M/2];
int main(){
	int i,j,n,m;
	table[0]=table[1]=1;
	for(i=2;i<=M;i++)if(!table[i])for(j=2*i;j<=M;j+=i)table[j]=1;
	scanf("%d%d",&n,&m);
	vector<int>lst;
	vector<int>lst_val;
	int result=0,result_max=0,result_val;
	for(i=n;i<=m;i++)if(!table[i]){
		int h=_hash(i);
		for(;find(lst.begin(),lst.end(),h)!=lst.end();result--){
			lst.erase(lst.begin());
			lst_val.erase(lst_val.begin());
		}
		lst.push_back(h);
		lst_val.push_back(i);
		result++;
		if(result_max<=result){
			result_max=result;
			result_val=lst_val[0];
		}
	}
	printf("%d\n",result_val);
}
0