結果

問題 No.6 使いものにならないハッシュ
ユーザー たこしたこし
提出日時 2015-06-07 22:39:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,915 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 93,080 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 22:52:17
合計ジャッジ時間 1,807 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 3 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,352 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 3 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,352 KB
testcase_29 AC 3 ms
4,352 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:126:24: warning: ‘ansL’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << primeList[ansL] << endl;
                        ^

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long

using namespace std;

#define MAX_N 200001

bool prime[MAX_N];
vector<int> primeList;
vector<int> primeHash;

int K, N;

void init(){

	prime[0] = prime[1] = true;

	for (int i = 2; i <= N; i++){
		if (!prime[i]){
			if (i >= K)
				primeList.push_back(i);
			if (i*i > N)
				continue;
			for (int j = 2; i*j <= N; j++){
				prime[i*j] = true;
			}
		}
	}

}

bool used[11];

int Hash(int x){

	if (x < 10)
		return x;

	int ans = 0;
	while (x > 0){
		ans += x % 10;
		x /= 10;
	}

	return Hash(ans);

}

int main() {

	cin >> K >> N;

	init();

	int ans = 0;
	memset(used, 0, sizeof(used));

	for (int i = 0; i < primeList.size(); i++){
		primeHash.push_back(Hash(primeList[i]));
	}

	//[left,right]
	int left = 0, right = 0;
	int ansL;

	while (right < primeHash.size()){

		if (!used[primeHash[right]]){
			used[primeHash[right]] = true;
			right++;
			if (ans <= right - left){
				ansL = left;
			}
			ans = max(ans, right - left);
			continue;
		}

		else{
			while (true){
				used[primeHash[left]] = false;
				left++;
				if (primeHash[left - 1] == primeHash[right])
					break;
			}
			used[primeHash[right]] = true;
			right++;
			if (ans <= right - left){
				ansL = left;
			}
			ans = max(ans, right - left);
			continue;
		}
	
	}

	cout << primeList[ansL] << endl;

	return 0;
}
0