結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
ripity
|
| 提出日時 | 2024-08-25 13:57:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 235 ms / 3,000 ms |
| コード長 | 1,187 bytes |
| コンパイル時間 | 2,153 ms |
| コンパイル使用メモリ | 206,140 KB |
| 最終ジャッジ日時 | 2025-02-24 01:01:54 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M, K;
cin >> N >> M >> K;
vector A(N, vector<int>(M));
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
cin >> A[i][j];
}
}
int ok = 0, ng = 1000000001;
while(ok + 1 < ng) {
const int k = (ok + ng) / 2;
const int INF = N * M + 5;
vector dp(N, vector<int>(M, INF));
dp[0][0] = (A[0][0] < k);
deque<pair<int, int>> que;
que.push_back(make_pair(0, 0));
while(!que.empty()) {
auto [r, c] = que.front();
que.pop_front();
vector<pair<int, int>> v = {{r + 1, c}, {r - 1, c}, {r, c + 1}, {r, c - 1}};
for(auto [r2, c2] : v) {
if(0 <= r2 && r2 < N && 0 <= c2 && c2 < M) {
if(A[r2][c2] >= k && dp[r2][c2] > dp[r][c]) {
dp[r2][c2] = dp[r][c];
que.push_front(make_pair(r2, c2));
}else if(A[r2][c2] < k && dp[r2][c2] > dp[r][c] + 1) {
dp[r2][c2] = dp[r][c] + 1;
que.push_back(make_pair(r2, c2));
}
}
}
}
// cout << k << " : " << dp[N - 1][M - 1] << endl;
if(dp[N - 1][M - 1] > K) ng = k;
else ok = k;
}
cout << ok << endl;
}
ripity