結果
問題 | No.6 使いものにならないハッシュ |
ユーザー |
![]() |
提出日時 | 2020-03-27 20:05:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,618 bytes |
コンパイル時間 | 1,740 ms |
コンパイル使用メモリ | 168,824 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-01-02 09:16:26 |
合計ジャッジ時間 | 2,793 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 6 WA * 26 |
ソースコード
#include <bits/stdc++.h> #define int long long #define REP(i, b) for(int i = 0; i < (b); i++) #define REPS(i, b) for(int i = 1; i <= (b); i++) #define ALL(v) (v).begin(), (v).end() using namespace std; using pi = pair<int, int>; using vi = vector<int>; using vs = vector<string>; using vb = vector<bool>; using vpi = vector<pi>; using vvi = vector<vi>; using vvb = vector<vb>; const int INF = 1e10; const int MOD = 1e9+7; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } int h(int n) { int res = 0; while(n > 0) { res += n % 10; n /= 10; } if(res >= 10) return h(res); return res; } signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); const int MAX = 200000; int K, N; cin >> K >> N; vb prime(MAX+1, true); prime[0] = prime[1] = false; for(int i = 2; i * i <= MAX; i++) { if(prime[i]) { for(int j = 2*i; j <= MAX; j += i) prime[j] = false; } } vpi table; for(int i = K; i <= N; i++) if(prime[i]) table.push_back(make_pair(i, h(i))); int len = 0, x = table[0].first; int l = 0, r = 0; vi m(10, 0); for(int l = 0; l < table.size(); l++) { while(r < N && m[table[r].second] == 0) { m[table[r].second]++; r++; } if(chmax(len, r-l)) x = table[l].first; m[table[l].second]--; } cout << x << endl; }