結果
問題 |
No.1460 Max of Min
|
ユーザー |
![]() |
提出日時 | 2021-03-31 22:47:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,333 bytes |
コンパイル時間 | 1,851 ms |
コンパイル使用メモリ | 177,080 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-12-15 21:04:41 |
合計ジャッジ時間 | 19,372 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 RE * 1 |
other | AC * 51 RE * 39 TLE * 1 |
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int gcd(int a, int b) { while (a && b) { if (a > b) a %= b; else b %= a; } return a + b; } int main() { int k = ri(); int64_t n; std::cin >> n; std::vector<int64_t> a(k + k); for (auto &i : a) std::cin >> i; std::reverse(a.begin() + k, a.end()); if (n < k) { printf("%" PRId64 "\n", a[n]); return 0; } int threashold = 1.5 * k * k; int index[k + k]; std::iota(index, index + k + k, 0); std::sort(index, index + k + k, [&] (int i, int j) { return a[i] > a[j]; }); std::set<int> start; std::set<int> move; for (auto i : index) { if (i < k) start.insert(i); else move.insert(i - k + 1); if (!move.size()) continue; int g = 0; for (auto j : move) g = gcd(g, j); // std::cerr << "added " << i << std::endl; bool ok = false; if (n > threashold) { assert(0); for (auto i : start) if ((n - i) % g == 0) ok = true; } else { bool dp[threashold + 1]; memset(dp, 0, sizeof(dp)); for (auto i : start) dp[i] = true; for (int i = 0; i < threashold; i++) { if (!dp[i]) continue; for (auto j : move) if (i + j <= threashold && i + j >= k) dp[i + j] = true; } if (dp[n]) ok = true; } if (ok) { printf("%" PRId64 "\n", a[i]); return 0; } } assert(0); return 0; }