結果

問題 No.2855 Move on Grid
ユーザー ripityripity
提出日時 2024-08-25 13:57:54
言語 C++17
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
6,812 KB
testcase_01 AC 82 ms
6,940 KB
testcase_02 AC 48 ms
6,940 KB
testcase_03 AC 38 ms
6,940 KB
testcase_04 AC 27 ms
6,944 KB
testcase_05 AC 57 ms
6,944 KB
testcase_06 AC 54 ms
6,944 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 46 ms
6,944 KB
testcase_09 AC 22 ms
6,944 KB
testcase_10 AC 164 ms
6,940 KB
testcase_11 AC 167 ms
6,944 KB
testcase_12 AC 166 ms
6,940 KB
testcase_13 AC 165 ms
6,940 KB
testcase_14 AC 169 ms
6,940 KB
testcase_15 AC 166 ms
6,940 KB
testcase_16 AC 166 ms
6,940 KB
testcase_17 AC 165 ms
6,944 KB
testcase_18 AC 166 ms
6,940 KB
testcase_19 AC 166 ms
6,940 KB
testcase_20 AC 276 ms
6,944 KB
testcase_21 AC 247 ms
6,940 KB
testcase_22 AC 248 ms
6,944 KB
testcase_23 AC 246 ms
6,944 KB
testcase_24 AC 247 ms
6,940 KB
testcase_25 AC 243 ms
6,944 KB
testcase_26 AC 248 ms
6,944 KB
testcase_27 AC 250 ms
6,940 KB
testcase_28 AC 248 ms
6,944 KB
testcase_29 AC 253 ms
6,940 KB
testcase_30 AC 243 ms
6,940 KB
testcase_31 AC 243 ms
6,940 KB
testcase_32 AC 245 ms
6,944 KB
testcase_33 AC 242 ms
6,940 KB
testcase_34 AC 241 ms
6,940 KB
testcase_35 AC 233 ms
6,940 KB
testcase_36 AC 213 ms
6,944 KB
testcase_37 AC 244 ms
6,940 KB
testcase_38 AC 240 ms
6,940 KB
testcase_39 AC 242 ms
6,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0