結果
問題 | No.2855 Move on Grid |
ユーザー | eve__fuyuki |
提出日時 | 2024-08-25 20:09:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 133 ms / 3,000 ms |
コード長 | 1,296 bytes |
コンパイル時間 | 2,490 ms |
コンパイル使用メモリ | 217,900 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-25 20:09:37 |
合計ジャッジ時間 | 7,968 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
6,812 KB |
testcase_01 | AC | 42 ms
6,940 KB |
testcase_02 | AC | 26 ms
6,940 KB |
testcase_03 | AC | 20 ms
6,940 KB |
testcase_04 | AC | 16 ms
6,944 KB |
testcase_05 | AC | 31 ms
6,940 KB |
testcase_06 | AC | 33 ms
6,944 KB |
testcase_07 | AC | 4 ms
6,944 KB |
testcase_08 | AC | 25 ms
6,940 KB |
testcase_09 | AC | 14 ms
6,944 KB |
testcase_10 | AC | 92 ms
6,940 KB |
testcase_11 | AC | 90 ms
6,940 KB |
testcase_12 | AC | 94 ms
6,940 KB |
testcase_13 | AC | 90 ms
6,940 KB |
testcase_14 | AC | 90 ms
6,944 KB |
testcase_15 | AC | 92 ms
6,940 KB |
testcase_16 | AC | 92 ms
6,940 KB |
testcase_17 | AC | 89 ms
6,940 KB |
testcase_18 | AC | 92 ms
6,944 KB |
testcase_19 | AC | 93 ms
6,944 KB |
testcase_20 | AC | 131 ms
6,940 KB |
testcase_21 | AC | 129 ms
6,944 KB |
testcase_22 | AC | 133 ms
6,944 KB |
testcase_23 | AC | 128 ms
6,940 KB |
testcase_24 | AC | 124 ms
6,940 KB |
testcase_25 | AC | 122 ms
6,940 KB |
testcase_26 | AC | 126 ms
6,940 KB |
testcase_27 | AC | 125 ms
6,940 KB |
testcase_28 | AC | 123 ms
6,944 KB |
testcase_29 | AC | 127 ms
6,940 KB |
testcase_30 | AC | 125 ms
6,940 KB |
testcase_31 | AC | 129 ms
6,944 KB |
testcase_32 | AC | 124 ms
6,944 KB |
testcase_33 | AC | 122 ms
6,944 KB |
testcase_34 | AC | 129 ms
6,940 KB |
testcase_35 | AC | 119 ms
6,940 KB |
testcase_36 | AC | 105 ms
6,940 KB |
testcase_37 | AC | 125 ms
6,940 KB |
testcase_38 | AC | 122 ms
6,944 KB |
testcase_39 | AC | 125 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); 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 dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; auto is_valid = [&](int x, int y) { return 0 <= x && x < n && 0 <= y && y < m; }; int ok = 1, ng = 1e9 + 1; while (ok + 1 < ng) { int mid = (ok + ng) / 2; vector<vector<int>> dp(n, vector<int>(m, 1e9)); vector<vector<bool>> vis(n, vector<bool>(m)); dp[0][0] = a[0][0] < mid; deque<pair<int, int>> dq; dq.push_back({0, 0}); while (!dq.empty()) { auto [x, y] = dq.front(); dq.pop_front(); if (vis[x][y]) { continue; } vis[x][y] = true; for (int i = 0; i < 4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if (!is_valid(nx, ny)) { continue; } int cost = (a[nx][ny] < mid); if (dp[nx][ny] > dp[x][y] + cost) { dp[nx][ny] = dp[x][y] + cost; if (cost == 0) { dq.push_front({nx, ny}); } else { dq.push_back({nx, ny}); } } } } if (dp[n - 1][m - 1] <= k) { ok = mid; } else { ng = mid; } } cout << ok << endl; }