結果

問題 No.6 使いものにならないハッシュ
ユーザー btkbtk
提出日時 2015-05-03 15:16:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,250 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 88,544 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:52:08
合計ジャッジ時間 2,189 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 8 ms
4,352 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 4 ms
4,348 KB
testcase_08 AC 5 ms
4,352 KB
testcase_09 AC 3 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 4 ms
4,352 KB
testcase_17 AC 6 ms
4,348 KB
testcase_18 AC 8 ms
4,352 KB
testcase_19 AC 6 ms
4,348 KB
testcase_20 AC 6 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 6 ms
4,352 KB
testcase_23 AC 6 ms
4,352 KB
testcase_24 AC 5 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 6 ms
4,348 KB
testcase_27 AC 5 ms
4,356 KB
testcase_28 AC 4 ms
4,352 KB
testcase_29 AC 7 ms
4,348 KB
testcase_30 AC 6 ms
4,348 KB
testcase_31 AC 5 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
int Hash(string s){
	int n = (int)s.size(),t=0;
	if (n == 1)return(stoi(s));
	for (int i = 0; i < n; i++)
	{
		t += s[i] - '0';
	}
	return Hash(to_string(t));
}

bool prime[1000000];
vector<int> prime_list;
vector<int> hash_list;
int table[10] = { 0 };
int len = 1, st = 0;
int main(void){
	int K, N;
	cin >> K >> N;
	for (int i = 0; i <= N; i++)
	{
		prime[i] = true;
	}
	prime[0] = prime[1] = false;
	for (int i = 0; i <= N; i++)
	{
		if (prime[i]){
			for (int j = (i << 1); j <= N; j += i)
			{
				prime[j] = false;
			}
			if (i >= K){
				prime_list.push_back(i);
				hash_list.push_back(Hash(to_string(i)));
			}
		}
	}
	st = prime_list[0];
	table[hash_list[0]]++;
	int l = 0, r = 1;
	while (r < ((int)prime_list.size())){
		while (table[hash_list[r]]>0)
			table[hash_list[l++]]--;

		if (len <= (r - l + 1))len = (r - l + 1), st = prime_list[l];
		table[hash_list[r++]]++;
	}
	cout << st << endl;
	return 0;
}
0