結果

問題 No.2855 Move on Grid
ユーザー GOTKAKOGOTKAKO
提出日時 2024-08-25 13:48:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 3,000 ms
コード長 1,214 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 213,796 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 13:48:23
合計ジャッジ時間 7,180 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
6,812 KB
testcase_01 AC 42 ms
6,940 KB
testcase_02 AC 22 ms
6,944 KB
testcase_03 AC 19 ms
6,940 KB
testcase_04 AC 14 ms
6,940 KB
testcase_05 AC 29 ms
6,944 KB
testcase_06 AC 29 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 23 ms
6,944 KB
testcase_09 AC 12 ms
6,940 KB
testcase_10 AC 87 ms
6,940 KB
testcase_11 AC 82 ms
6,940 KB
testcase_12 AC 83 ms
6,944 KB
testcase_13 AC 81 ms
6,940 KB
testcase_14 AC 84 ms
6,940 KB
testcase_15 AC 85 ms
6,944 KB
testcase_16 AC 84 ms
6,940 KB
testcase_17 AC 84 ms
6,940 KB
testcase_18 AC 85 ms
6,940 KB
testcase_19 AC 84 ms
6,944 KB
testcase_20 AC 122 ms
6,940 KB
testcase_21 AC 121 ms
6,944 KB
testcase_22 AC 122 ms
6,940 KB
testcase_23 AC 123 ms
6,940 KB
testcase_24 AC 126 ms
6,944 KB
testcase_25 AC 118 ms
6,944 KB
testcase_26 AC 124 ms
6,940 KB
testcase_27 AC 121 ms
6,940 KB
testcase_28 AC 119 ms
6,940 KB
testcase_29 AC 124 ms
6,940 KB
testcase_30 AC 118 ms
6,940 KB
testcase_31 AC 120 ms
6,944 KB
testcase_32 AC 118 ms
6,940 KB
testcase_33 AC 119 ms
6,940 KB
testcase_34 AC 117 ms
6,940 KB
testcase_35 AC 114 ms
6,944 KB
testcase_36 AC 101 ms
6,944 KB
testcase_37 AC 117 ms
6,940 KB
testcase_38 AC 118 ms
6,944 KB
testcase_39 AC 119 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N,M,K; cin >> N >> M >> K;
    vector<vector<int>> A(N,vector<int>(M));
    for(auto &h : A) for(auto &w : h) cin >> w;

    int low = 0,high = 1000000001;
    while(high-low > 1){
        int mid = (high+low)/2;
        vector<pair<int,int>> dxy = {{-1,0},{0,1},{1,0},{0,-1}};
        vector<vector<int>> dist(N,vector<int>(M,1001001001));
        if(A.at(0).at(0) < mid) dist.at(0).at(0) = 1;
        else dist.at(0).at(0) = 0;

        deque<pair<int,int>> Q; Q.push_back({0,0});
        while(Q.size()){
            auto [x,y] = Q.front(); Q.pop_front();
            for(auto [dx,dy] : dxy){
                int nx = dx+x,ny = dy+y;
                if(nx < 0 || nx >= N || ny < 0 || ny >= M) continue;
                if(dist.at(nx).at(ny) != 1001001001) continue;
                if(A.at(nx).at(ny) >= mid) dist.at(nx).at(ny) = dist.at(x).at(y),Q.push_front({nx,ny});
                else dist.at(nx).at(ny) = dist.at(x).at(y)+1,Q.push_back({nx,ny});
            }
        }
        if(dist.at(N-1).at(M-1) > K) high = mid;
        else low = mid;
    }
    cout << low << endl;
}
0