結果
問題 |
No.6 使いものにならないハッシュ
|
ユーザー |
![]() |
提出日時 | 2014-10-29 10:31:25 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,543 bytes |
コンパイル時間 | 969 ms |
コンパイル使用メモリ | 75,644 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-30 13:33:52 |
合計ジャッジ時間 | 1,949 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 WA * 29 |
ソースコード
#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)); used[mhash(memo[0])] = true; for (int l = 0, r = 1; r < memo.size(); r++) { if (used[mhash(memo[r])] || r == memo.size()-1) { if (maxi <= r-l) { maxi = r-l; ans = memo[l]; } while (mhash(memo[l]) != mhash(memo[r])) { used[mhash(memo[l])] = false; l++; } l++; if (l < memo.size() && maxi <= r-l+1) { maxi = r-l+1; ans = memo[l]; } } } if (!maxi) { cout << memo[memo.size()-1] << endl; }else { cout << ans << endl; } }