結果

問題 No.6 使いものにならないハッシュ
ユーザー ldsybldsyb
提出日時 2017-06-16 23:13:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 778 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 72,800 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:06:07
合計ジャッジ時間 1,869 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,352 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,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 3 ms
4,352 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 3 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:32:17: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   32 |         cout << ans << endl;
      |                 ^~~
main.cpp:22:17: 備考: ‘ans’ はここで定義されています
   22 |         int32_t ans, maxi = 0, lastp[10]{};
      |                 ^~~

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int32_t> make_primes(int32_t a, int32_t b){
	vector<int32_t> ps;
	bool e[b + 1];
	fill(e, e + b + 1, true);
	for(int32_t i = 2; i <= b; i++) if(e[i]){
		if(a <= i) ps.emplace_back(i);
		for(int32_t j = 2 * i; j <= b; j += i) e[j] = false;
	}
	return ps;
}

int main(){
	int32_t a, b;
	cin >> a >> b;
	vector<int32_t> ps = make_primes(a, b), hashed = ps;
	for(auto& p:hashed) while(10 <= p) p = p / 10 + p % 10;
	int32_t ans, maxi = 0, lastp[10]{};
	for(int32_t i = 0, lpmax = 0; i < hashed.size(); i++){
		lpmax = max(lpmax, lastp[hashed[i]]);
		int32_t dist = i - lpmax + 1;
		if(maxi <= dist){
			maxi = dist;
			ans = ps[lpmax + 1];
		}
		lastp[hashed[i]] = i;
	}
	cout << ans << endl;
}
0