結果
| 問題 | No.6 使いものにならないハッシュ | 
| コンテスト | |
| ユーザー |  ldsyb | 
| 提出日時 | 2017-06-16 23:13:39 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                            (最新) 
                                AC
                                 
                            (最初) | 
| 実行時間 | - | 
| コード長 | 778 bytes | 
| コンパイル時間 | 727 ms | 
| コンパイル使用メモリ | 73,424 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:39:40 | 
| 合計ジャッジ時間 | 1,723 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 31 WA * 1 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:32:17: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
   32 |         cout << ans << endl;
      |                 ^~~
main.cpp:22:17: note: 'ans' was declared here
   22 |         int32_t ans, maxi = 0, lastp[10]{};
      |                 ^~~
            
            ソースコード
#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;
}
            
            
            
        