結果
| 問題 |
No.6 使いものにならないハッシュ
|
| コンテスト | |
| ユーザー |
k
|
| 提出日時 | 2014-10-29 13:36:28 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,367 bytes |
| コンパイル時間 | 779 ms |
| コンパイル使用メモリ | 75,808 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 13:38:36 |
| 合計ジャッジ時間 | 2,094 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 13 WA * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:62:11: warning: ‘ans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | cout << ans << endl;
| ^~~
ソースコード
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
int mhash(int x) {
while (x%10 != x) {
int t = 0;
for (int i = x; i != 0; i/=10) t += i%10;
x = t;
}
return x;
}
int main() {
int k, n;
cin >> k >> n;
bool not_prime[n+1];
memset(not_prime, false, sizeof(not_prime));
not_prime[1] = true;
for (int i = 2; i <= n; i++) {
for (int j = i+i; j <= n; j+=i) {
not_prime[j] = true;
}
}
// for (int i = 0; i <= n; i++) cout << i << ": " << not_prime[i] << endl;
vector <int> memo;
for (int i = k; i <= n; i++) if (!not_prime[i]) memo.push_back(i);
// for (int i = 0; i < memo.size(); i++) cout << mhash(memo[i]) << endl;
int ans, maxi = 0;
bool used[10]; memset(used, false, sizeof(used));
for (int l = 0, r = 0; r <= memo.size(); r++) {
if (used[mhash(memo[r])]) {
while (mhash(memo[l]) != mhash(memo[r])) {
used[mhash(memo[l])] = false;
l++;
}
l++;
}
if (maxi <= r-l+1) {
maxi = r-l+1;
ans = memo[l];
}
used[mhash(memo[r])] = true;
}
cout << ans << endl;
}
k