結果

問題 No.6 使いものにならないハッシュ
ユーザー 37kt_37kt_
提出日時 2015-10-28 11:35:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 1,273 ms
コンパイル使用メモリ 148,416 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 22:55:47
合計ジャッジ時間 3,366 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 55 ms
4,352 KB
testcase_03 AC 9 ms
4,352 KB
testcase_04 AC 12 ms
4,352 KB
testcase_05 AC 16 ms
4,348 KB
testcase_06 AC 29 ms
4,348 KB
testcase_07 AC 16 ms
4,352 KB
testcase_08 AC 25 ms
4,352 KB
testcase_09 AC 9 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 10 ms
4,348 KB
testcase_12 AC 36 ms
4,352 KB
testcase_13 AC 6 ms
4,352 KB
testcase_14 AC 9 ms
4,348 KB
testcase_15 AC 28 ms
4,352 KB
testcase_16 AC 19 ms
4,352 KB
testcase_17 AC 39 ms
4,352 KB
testcase_18 AC 53 ms
4,348 KB
testcase_19 AC 38 ms
4,348 KB
testcase_20 AC 34 ms
4,348 KB
testcase_21 AC 6 ms
4,348 KB
testcase_22 AC 35 ms
4,352 KB
testcase_23 AC 34 ms
4,348 KB
testcase_24 AC 34 ms
4,348 KB
testcase_25 AC 19 ms
4,348 KB
testcase_26 AC 43 ms
4,348 KB
testcase_27 AC 31 ms
4,348 KB
testcase_28 AC 20 ms
4,352 KB
testcase_29 AC 46 ms
4,352 KB
testcase_30 AC 41 ms
4,352 KB
testcase_31 AC 36 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, m;
int cnt[10];

bool isprime(int x)
{
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++){
		if (x % i == 0) return false;
	}
	return true;
}

int hash_(int x)
{
	stringstream ss;
	ss << x;
	
	string s;
	ss >> s;
	if (s.size() == 1) return s[0] - '0';
	int sum = 0;
	for (char c : s) sum += c - '0';
	return hash_(sum);
}

int main()
{
	cin >> n >> m;
	
	vector<int> ps;
	vector<int> hs;
	for (int i = n; i <= m; i++){
		if (isprime(i)){
			ps.push_back(i);
			hs.push_back(hash_(i));
		}
	}

	int l = 0, r = 0;
	int len = 0, res = 0;
	while (r < ps.size()){
		cnt[hs[r]]++;
		while (cnt[hs[r]] == 2){
			cnt[hs[l++]]--;
		}
		if (len <= r - l + 1){
			res = ps[l];
			len = r - l + 1;
		}
		r++;
	}

	cout << res << endl;
}
0