結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-25 14:13:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,201 bytes |
| コンパイル時間 | 2,022 ms |
| コンパイル使用メモリ | 198,144 KB |
| 最終ジャッジ日時 | 2025-02-24 01:06:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 WA * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> istream& operator >> (istream& is, vector<T>& vec) {
for(T& x : vec) is >> x;
return is;
}
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
if(vec.empty()) return os;
os << vec[0];
for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
return os;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, k;
cin >> h >> w >> k;
if(k > h + w){
cout << 1'000'000'000 << '\n';
return 0;
}
vector A(h, vector<int>(w));
cin >> A;
k = min(k, h + w);
int ok = 0, ng = 1'000'000'005;
while(ok + 1 < ng){
int mid = (ok + ng) / 2;
vector dp(h, vector<int>(w, 1 << 30));
dp[0][0] = A[0][0] < mid;
for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
if(y + 1 < h) dp[y + 1][x] = min(dp[y + 1][x], dp[y][x] + (A[y + 1][x] < mid));
if(x + 1 < w) dp[y][x + 1] = min(dp[y][x + 1], dp[y][x] + (A[y][x + 1] < mid));
}
}
(dp[h - 1][w - 1] <= k ? ok : ng) = mid;
}
cout << ok << '\n';
}