結果

問題 No.6 使いものにならないハッシュ
ユーザー tkzw_21tkzw_21
提出日時 2014-12-21 14:37:22
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,101 bytes
コンパイル時間 2,427 ms
コンパイル使用メモリ 75,668 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-09-02 20:49:01
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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=k,l=k;r<arr.size();r++){
		while(used[myhash(arr[r])]){
			used[myhash(arr[l])] = false;
			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++){
		if(width[arr[i]] >= var){
			var = width[arr[i]];
			ret = arr[i];
		}
	}
	cout << ret << endl;

	return 0;
}
0