結果
| 問題 |
No.1460 Max of Min
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-01 07:34:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,149 bytes |
| コンパイル時間 | 1,325 ms |
| コンパイル使用メモリ | 86,620 KB |
| 最終ジャッジ日時 | 2025-01-20 04:54:33 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 69 WA * 22 |
ソースコード
#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/heap_alias.hpp"
#include <queue>
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
#line 2 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using lint = long long;
constexpr lint INF = 1LL << 60;
void solve() {
int k;
lint n;
cin >> k >> n;
vector<lint> xs(k), ys(k);
for (auto& x : xs) cin >> x;
for (auto& y : ys) cin >> y;
if (n < k) {
cout << xs[n] << "\n";
return;
}
lint ok = -INF, ng = INF;
while (ng - ok > 1) {
auto mid = (ok + ng) / 2;
vector<int> ts; // { k-j | ys[j] >= mid }
for (int j = 0; j < k; ++j) {
if (ys[j] >= mid) ts.push_back(k - j);
}
if (ts.empty()) {
ng = mid;
continue;
}
auto m = ts.back(); // minimum
while (m < k) m <<= 1;
// 小さすぎると遷移できない場合があるので、十分に拡張
// mod m でDijkstra
vector<lint> dist(m, INF);
MinHeap<pair<lint, int>> heap;
for (int i = 0; i < k; ++i) {
if (xs[i] >= mid) {
dist[i] = i;
heap.emplace(i, i);
}
}
while (!heap.empty()) {
auto [d, i] = heap.top();
heap.pop();
if (d > dist[i]) continue;
for (auto t : ts) {
auto ni = (i + t) % m;
auto nd = d + t;
if (nd < dist[ni]) {
dist[ni] = nd;
heap.emplace(nd, ni);
}
}
}
bool valid = false;
for (int i = n % ts.back(); i < m; i += ts.back()) {
if (dist[i] <= n) valid = true;
}
if (valid) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok << "\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}