結果

問題 No.6 使いものにならないハッシュ
ユーザー tkzw_21tkzw_21
提出日時 2014-12-21 14:56:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,261 bytes
コンパイル時間 539 ms
コンパイル使用メモリ 75,804 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 22:47:51
合計ジャッジ時間 1,770 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
#define INF 114514

using namespace std;

typedef pair<int,int> P;

int myhash(int n){
	if(n/10 == 0)return n;

	int sum = 0;
	while(n!=0){
		sum += n%10;
		n /= 10;
	}
	return myhash(sum);
}

vector<int> eratosthenes_sieve(int n){
	vector<int> table(n+1);
	vector<int> prime_list;

	for(int i=2;i<n+1;i++){
		if(table[i] == 0){
			prime_list.push_back(i);
			for(int j=i+i;j<n+1;j+=i)
				table[j] = 1;
		}
	}
	return prime_list;
}


int main(void){
	int k,n;
	cin >> k >> n;
	vector<int> arr = eratosthenes_sieve(n);

	bool used[10] = {0};
	vector<int> width(n+1);


	int haba = 0;
	for(int r=0,l=0;r<arr.size() && arr[r] <= n;r++){
		if(arr[r] < k){
			l++;
			continue;
		}
		while(used[myhash(arr[r])]){
			used[myhash(arr[l])] = false;
			l++;haba--;
			width[arr[l]] = haba;
		}

		used[myhash(arr[r])] = true;
		haba++;
		width[arr[l]] = haba;
	}

	int ret = 0,var = 0;
	for(int i=0;i<arr.size();i++){
		//cout << arr[i] << ":" << myhash(arr[i]) << ":"<< width[arr[i]] << endl;
		if(width[arr[i]] >= var){
			var = width[arr[i]];
			ret = arr[i];
		}
	}
	cout << ret << endl;

	return 0;
}
0