結果

問題 No.6 使いものにならないハッシュ
ユーザー moyashi_senpaimoyashi_senpai
提出日時 2016-08-19 02:00:20
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,334 bytes
コンパイル時間 927 ms
コンパイル使用メモリ 77,940 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-10-14 23:01:58
合計ジャッジ時間 2,032 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define REP(i,n) for(int i = 0; n > i; i++)

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;
int arr[200000];

void Eratosthenes(int N) {
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}
}

int ketasum(int n, int base) {//桁の総数 345->3+4+5
	if (n == 0)return 0;
	return ketasum(n - n%(base*10), base*10) + n % (base * 10) / base;
}

int main() {
	int a, b;
	scanf("%d %d", &a, &b);

	Eratosthenes(b+1);

	vector<int> sosu, hash;
	for (int i = max(a, 2); b+1 >= i; i++) {
		if (arr[i]) {
			int n = i;
			while ((n / 10)) {
				n = ketasum(n, 1);
			}
			sosu.push_back(i);
			hash.push_back(n);
		}
	}

	int ans = 0, ansst;
	for (int i = sosu.size() - 1; 0 <= i; i--) {
		array<bool, 10> al = {};
		for (int j = i; 0 <= j; j--) {
			if (al[hash[j]]) {
				if (ans < i - j)ansst = sosu[j+1];
				ans = max(ans, i-j);
				break;
			}
			else {
				al[hash[j]] = 1;
			}
		}
	}

	printf("%d\n", ansst);
	return 0;
}
0