結果
問題 | No.2855 Move on Grid |
ユーザー |
|
提出日時 | 2024-08-25 13:48:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 128 ms / 3,000 ms |
コード長 | 1,214 bytes |
コンパイル時間 | 2,165 ms |
コンパイル使用メモリ | 207,440 KB |
最終ジャッジ日時 | 2025-02-24 00:57:52 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {ios_base::sync_with_stdio(false);cin.tie(nullptr);int N,M,K; cin >> N >> M >> K;vector<vector<int>> A(N,vector<int>(M));for(auto &h : A) for(auto &w : h) cin >> w;int low = 0,high = 1000000001;while(high-low > 1){int mid = (high+low)/2;vector<pair<int,int>> dxy = {{-1,0},{0,1},{1,0},{0,-1}};vector<vector<int>> dist(N,vector<int>(M,1001001001));if(A.at(0).at(0) < mid) dist.at(0).at(0) = 1;else dist.at(0).at(0) = 0;deque<pair<int,int>> Q; Q.push_back({0,0});while(Q.size()){auto [x,y] = Q.front(); Q.pop_front();for(auto [dx,dy] : dxy){int nx = dx+x,ny = dy+y;if(nx < 0 || nx >= N || ny < 0 || ny >= M) continue;if(dist.at(nx).at(ny) != 1001001001) continue;if(A.at(nx).at(ny) >= mid) dist.at(nx).at(ny) = dist.at(x).at(y),Q.push_front({nx,ny});else dist.at(nx).at(ny) = dist.at(x).at(y)+1,Q.push_back({nx,ny});}}if(dist.at(N-1).at(M-1) > K) high = mid;else low = mid;}cout << low << endl;}