結果
問題 | No.2855 Move on Grid |
ユーザー |
![]() |
提出日時 | 2024-08-25 16:01:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 640 ms / 3,000 ms |
コード長 | 2,612 bytes |
コンパイル時間 | 3,787 ms |
コンパイル使用メモリ | 238,520 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-25 16:01:38 |
合計ジャッジ時間 | 18,321 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 40 |
ソースコード
//#pragma GCC optimize("Ofast")//#pragma GCC optimize("unroll-loops")#include <bits/stdc++.h>using namespace std;using ll = long long;using ld = long double;using P = pair<ll, ll>;using vi = vector<ll>;using vd = vector<ld>;using vP = vector<P>;using vvi = vector<vector<ll>>;using vvd = vector<vector<ld>>;using vvP = vector<vector<P>>;using vvvi = vector<vector<vector<ll>>>;using vvvd = vector<vector<vector<ld>>>;using vvvP = vector<vector<vector<P>>>;#if __has_include(<atcoder/all>)#include <atcoder/all>using namespace atcoder;using mint = modint998244353;using Mint = modint1000000007;using vm = vector<mint>;using vM = vector<Mint>;using vvm = vector<vector<mint>>;using vvM = vector<vector<Mint>>;using vvvm = vector<vector<vector<mint>>>;using vvvM = vector<vector<vector<Mint>>>;#endif#define rrep(i, n) for (ll i = (n)-1; (i) >= 0; --(i))#define rep(i, n) for (ll i = 0; (i) < (n); ++(i))#define reps(i, n) for (ll i = 1; (i) <= (n); ++(i))#define Rep(i,a,b) for(ll i = (a); i <= (b); i++)#define all(a) (a).begin(),(a).end()const ll MOD = 998244353;#define Yes(b) ((b)?"Yes":"No")#define YES(b) ((b)?"YES":"NO")#define ft first#define sd secondbool chmin(ll& a, ll b) { return a > b ? a = b, 1 : 0; }bool chmax(ll& a, ll b) { return a < b ? a = b, 1 : 0; }vi s90 = { 0, 1, 0, -1 }, c90 = { 1, 0, -1, 0 };vi s45 = { 0, 1, 1, 1, 0, -1, -1, -1 }, c45 = { 1, 1, 0, -1, -1, -1, 0, 1 };signed main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);cout << fixed << setprecision(20);ll N, M, K; cin >> N >> M >> K;vvi a(N, vi(M));rep(i, N){rep(k, M) cin >> a[i][k];}if(K > N + M - 2){cout << 1000000000 << endl;return 0;}ll L = 2, R = 1e9;auto solve = [&](ll m){vvi dp(N, vi(M, 1e9));if(a[0][0] >= m) dp[0][0] = 0;else dp[0][0] = 1;priority_queue<P, vP, greater<P>> Q; Q.push({dp[0][0], 0});while(!Q.empty()){ll p = Q.top().sd, c = Q.top().ft; Q.pop();rep(t, 4){ll h = p / M + s90[t], w = p % M + c90[t];if(h < 0 || w < 0 || h >= N || w >= M) continue;if(dp[h][w] == 1e9){if(a[h][w] < m) dp[h][w] = dp[p/M][p%M] + 1;else dp[h][w] = dp[p/M][p%M];Q.push({dp[h][w], h * M + w});}}}return dp[N-1][M-1];};while(L <= R){ll m = (L + R) / 2;if(solve(m) <= K) L = m + 1;else R = m - 1;}cout << R << endl;}