結果
問題 | No.2855 Move on Grid |
ユーザー | ripity |
提出日時 | 2024-08-25 13:57:54 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 276 ms / 3,000 ms |
コード長 | 1,187 bytes |
コンパイル時間 | 2,513 ms |
コンパイル使用メモリ | 213,556 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-08-25 13:58:06 |
合計ジャッジ時間 | 11,049 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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; }