結果

問題 No.2855 Move on Grid
ユーザー dyktr_06dyktr_06
提出日時 2023-10-24 20:10:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 3,000 ms
コード長 1,763 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 215,560 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 13:00:22
合計ジャッジ時間 8,497 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
6,816 KB
testcase_01 AC 60 ms
6,944 KB
testcase_02 AC 36 ms
6,940 KB
testcase_03 AC 28 ms
6,944 KB
testcase_04 AC 21 ms
6,940 KB
testcase_05 AC 40 ms
6,940 KB
testcase_06 AC 39 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 34 ms
6,944 KB
testcase_09 AC 16 ms
6,944 KB
testcase_10 AC 101 ms
6,944 KB
testcase_11 AC 102 ms
6,940 KB
testcase_12 AC 104 ms
6,944 KB
testcase_13 AC 105 ms
6,940 KB
testcase_14 AC 106 ms
6,944 KB
testcase_15 AC 106 ms
6,944 KB
testcase_16 AC 99 ms
6,940 KB
testcase_17 AC 102 ms
6,944 KB
testcase_18 AC 102 ms
6,940 KB
testcase_19 AC 104 ms
6,940 KB
testcase_20 AC 178 ms
6,940 KB
testcase_21 AC 175 ms
6,940 KB
testcase_22 AC 179 ms
6,940 KB
testcase_23 AC 184 ms
6,944 KB
testcase_24 AC 172 ms
6,940 KB
testcase_25 AC 181 ms
6,944 KB
testcase_26 AC 181 ms
6,944 KB
testcase_27 AC 175 ms
6,940 KB
testcase_28 AC 181 ms
6,940 KB
testcase_29 AC 179 ms
6,944 KB
testcase_30 AC 175 ms
6,940 KB
testcase_31 AC 175 ms
6,944 KB
testcase_32 AC 179 ms
6,940 KB
testcase_33 AC 175 ms
6,940 KB
testcase_34 AC 176 ms
6,944 KB
testcase_35 AC 170 ms
6,944 KB
testcase_36 AC 157 ms
6,944 KB
testcase_37 AC 171 ms
6,940 KB
testcase_38 AC 173 ms
6,940 KB
testcase_39 AC 176 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(cost[nx][ny] != -1){
                        continue;
                    }
                    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;
}
0