結果

問題 No.2855 Move on Grid
ユーザー shinchanshinchan
提出日時 2024-08-25 13:51:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 190 ms / 3,000 ms
コード長 1,767 bytes
コンパイル時間 2,319 ms
コンパイル使用メモリ 216,180 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 13:52:01
合計ジャッジ時間 8,267 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
6,816 KB
testcase_01 AC 53 ms
6,944 KB
testcase_02 AC 26 ms
6,940 KB
testcase_03 AC 25 ms
6,944 KB
testcase_04 AC 17 ms
6,940 KB
testcase_05 AC 37 ms
6,944 KB
testcase_06 AC 30 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 30 ms
6,944 KB
testcase_09 AC 11 ms
6,940 KB
testcase_10 AC 83 ms
6,940 KB
testcase_11 AC 89 ms
6,944 KB
testcase_12 AC 85 ms
6,944 KB
testcase_13 AC 87 ms
6,944 KB
testcase_14 AC 83 ms
6,940 KB
testcase_15 AC 89 ms
6,940 KB
testcase_16 AC 85 ms
6,940 KB
testcase_17 AC 84 ms
6,940 KB
testcase_18 AC 84 ms
6,944 KB
testcase_19 AC 90 ms
6,944 KB
testcase_20 AC 162 ms
6,940 KB
testcase_21 AC 190 ms
6,940 KB
testcase_22 AC 157 ms
6,944 KB
testcase_23 AC 182 ms
6,944 KB
testcase_24 AC 162 ms
6,940 KB
testcase_25 AC 164 ms
6,940 KB
testcase_26 AC 166 ms
6,940 KB
testcase_27 AC 158 ms
6,940 KB
testcase_28 AC 167 ms
6,940 KB
testcase_29 AC 161 ms
6,940 KB
testcase_30 AC 172 ms
6,940 KB
testcase_31 AC 171 ms
6,940 KB
testcase_32 AC 152 ms
6,940 KB
testcase_33 AC 175 ms
6,940 KB
testcase_34 AC 172 ms
6,944 KB
testcase_35 AC 146 ms
6,940 KB
testcase_36 AC 143 ms
6,944 KB
testcase_37 AC 154 ms
6,940 KB
testcase_38 AC 174 ms
6,944 KB
testcase_39 AC 157 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

void chmax(ll &a, ll b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, k;
    cin >> n >> m >> k;
    int dy[4] = {-1, 0, 0, 1};
    int dx[4] = {0, -1, 1, 0};
    vector a(n, vector(m, 0LL));
    rep(i, n) rep(j, m) cin >> a[i][j];
    ll le = 0, ri = 1000000001;
    while(ri - le > 1) {
        ll mid = (ri + le) / 2;
        vector b(n, vector(m, 0));
        rep(i, n) rep(j, m) if(a[i][j] >= mid) b[i][j] = 1;
        vector dis(n, vector(m, 1 << 30));
        deque<pair<int, int>> dq;
        if(b[0][0]) dis[0][0] = 0;
        else dis[0][0] = 1;
        dq.push_back({0, 0});
        while(!dq.empty()) {
            auto [i, j] = dq.front();
            dq.pop_front();
            rep(kk, 4) {
                int y = i + dy[kk];
                int x = j + dx[kk];
                if(y < 0 or y >= n or x < 0 or x >= m) continue;
                if(b[y][x]) {
                    if(dis[y][x] > dis[i][j]) {
                        dis[y][x] = dis[i][j];
                        dq.push_front({y, x});
                    }
                } else {
                    if(dis[y][x] > dis[i][j] + 1) {
                        dis[y][x] = dis[i][j] + 1;
                        dq.push_back({y, x});
                    }
                }
            }
        }
        if(dis[n - 1][m - 1] <= k) le = mid;
        else ri = mid;
    }
    cout << le << endl;
    return 0;
}
0