結果
問題 |
No.2855 Move on Grid
|
ユーザー |
|
提出日時 | 2023-10-24 15:13:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 220 ms / 3,000 ms |
コード長 | 1,663 bytes |
コンパイル時間 | 2,066 ms |
コンパイル使用メモリ | 206,476 KB |
最終ジャッジ日時 | 2025-02-17 13:28:37 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int> dx = {0, 1, 0, -1}; vector<int> dy = {1, 0, -1, 0}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; vector<vector<int>> 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 = 1, ng = 1000000000 + 1; while(abs(ok - ng) > 1){ int mid = (ok + ng) / 2; vector<vector<int>> b(n, vector<int>(m)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ if(a[i][j] < mid){ b[i][j] = 1; }else{ b[i][j] = 0; } } } vector<vector<int>> cost(n, vector<int>(m, -1)); deque<tuple<int, int, int>> deq; deq.emplace_back(b[0][0], 0, 0); while(deq.size()){ auto [dist, x, y] = deq.front(); deq.pop_front(); if(cost[x][y] != -1){ continue; } cost[x][y] = dist; for(int dir = 0; dir < 4; dir++){ int nx = x + dx[dir], ny = y + dy[dir]; if(0 <= nx && nx < n && 0 <= ny && ny < m){ if(b[nx][ny] == 0){ deq.emplace_front(dist, nx, ny); }else{ deq.emplace_back(dist + 1, nx, ny); } } } } if(cost[n - 1][m - 1] <= k){ ok = mid; }else{ ng = mid; } } cout << ok << endl; }