結果
問題 | No.2855 Move on Grid |
ユーザー |
![]() |
提出日時 | 2024-08-25 13:55:13 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 176 ms / 3,000 ms |
コード長 | 1,889 bytes |
コンパイル時間 | 3,384 ms |
コンパイル使用メモリ | 277,048 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-08-25 13:55:28 |
合計ジャッジ時間 | 8,810 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic warning "-Wunused-function"using namespace std;using namespace atcoder;#define rep(i,n) for(int i = 0; i < (int)(n); i++)#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)#define all(x) begin(x), end(x)#define rall(x) rbegin(x), rend(x)template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;const int di[] = {1, 0, -1, 0};const int dj[] = {0, 1, 0, -1};int a[301][301];bool done[301][301];int dist[301][301];} int main() {ios::sync_with_stdio(false);cin.tie(0);int n, m, k;cin >> n >> m >> k;rep(i, n) rep(j, m) cin >> a[i][j];int l = 0, r = 1e9 + 1;while (r - l > 1) {int c = (l + r) / 2;constexpr int INF = 1001001001;rep(i, n) rep(j, m) done[i][j] = false, dist[i][j] = INF;deque<P> q;if (a[0][0] >= c) dist[0][0] = 0, q.emplace_front(0, 0);else dist[0][0] = 1, q.emplace_back(0, 0);auto idxchk = [&](int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; };while (q.size()) {auto [i, j] = q.front(); q.pop_front();if (done[i][j]) continue;done[i][j] = true;rep(k, 4) {int ni = i + di[k], nj = j + dj[k];if (!idxchk(ni, nj)) continue;if (a[ni][nj] >= c && dist[ni][nj] > dist[i][j]) dist[ni][nj] = dist[i][j], q.emplace_front(ni, nj);else if (dist[ni][nj] > dist[i][j] + 1) dist[ni][nj] = dist[i][j] + 1, q.emplace_back(ni, nj);}}(dist[n-1][m-1] <= k ? l : r) = c;}cout << l << '\n';}