結果

問題 No.6 使いものにならないハッシュ
ユーザー Naoyk1212Naoyk1212
提出日時 2017-06-09 15:13:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,516 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 96,992 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 20:46:51
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;

vector<int> primes;

void sieve(int n) {
	bool isPrime[200010];
	for (int i = 0; i < 200010; i++)isPrime[i] = true;
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 0; i <= n; i++) {
		if (isPrime[i] == true) {
			primes.push_back(i);
			for (int j = i * 2; j <= n; j += i) {
				isPrime[j] = false;
			}
		}
	}
}

int FrankHash(int n) {
	int tmp = 0;
	while (n > 0) {
		tmp += n % 10;
		n /= 10;
		if (tmp >= 10) {
			tmp = tmp % 10 + tmp / 10;
		}
	}
	return tmp;
}

int main() {
	int k, n;
	cin >> k >> n;
	sieve(n);
	vector<int> v;
	vector<int> hashed;
	for (int i = 0; i < primes.size(); i++) {
		if (primes[i] >= k && primes[i] <= n)v.push_back(primes[i]);
	}

	for (int i = 0; i < v.size(); i++) {
		hashed.push_back(FrankHash(v[i]));
	}

	map<int, bool> mp;
	for (int i = 1; i < 10; i++) {
		mp[i] = false;
	}

	int s = 0;
	int t = 0;
	int mx = 0;
	int mx_len = 0;
	mp[hashed[s]] = true;
	while (1) {
		while (t < v.size() && !mp[hashed[t]]) {
			mp[hashed[t++]] = true;
			//cerr << v[s] << " " << v[t] << endl;
		}
		if (s == v.size())break;

		if (mx_len < t - s) {
			mx_len = t - s;
			mx = v[s];
		}
		else if (mx_len == t - s) {
			mx = max(mx, v[s]);
		}

		mp[hashed[s++]] = false;
		cerr << mx << " " << mx_len << endl;
	}
	cout << mx << endl;

}
0