結果

問題 No.2855 Move on Grid
ユーザー aogeraaogera
提出日時 2024-08-29 21:13:34
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 302 ms / 3,000 ms
コード長 3,072 bytes
コンパイル時間 8,081 ms
コンパイル使用メモリ 350,808 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-29 21:13:56
合計ジャッジ時間 18,633 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
6,812 KB
testcase_01 AC 87 ms
6,940 KB
testcase_02 AC 58 ms
6,944 KB
testcase_03 AC 42 ms
6,940 KB
testcase_04 AC 31 ms
6,940 KB
testcase_05 AC 61 ms
6,944 KB
testcase_06 AC 62 ms
6,940 KB
testcase_07 AC 7 ms
6,944 KB
testcase_08 AC 49 ms
6,940 KB
testcase_09 AC 25 ms
6,944 KB
testcase_10 AC 234 ms
6,940 KB
testcase_11 AC 259 ms
6,948 KB
testcase_12 AC 233 ms
6,944 KB
testcase_13 AC 233 ms
6,940 KB
testcase_14 AC 236 ms
6,940 KB
testcase_15 AC 236 ms
6,940 KB
testcase_16 AC 248 ms
6,940 KB
testcase_17 AC 231 ms
6,940 KB
testcase_18 AC 238 ms
6,940 KB
testcase_19 AC 236 ms
6,944 KB
testcase_20 AC 269 ms
6,944 KB
testcase_21 AC 302 ms
6,940 KB
testcase_22 AC 278 ms
6,940 KB
testcase_23 AC 269 ms
6,944 KB
testcase_24 AC 273 ms
6,940 KB
testcase_25 AC 301 ms
6,944 KB
testcase_26 AC 273 ms
6,940 KB
testcase_27 AC 273 ms
6,944 KB
testcase_28 AC 274 ms
6,944 KB
testcase_29 AC 289 ms
6,940 KB
testcase_30 AC 272 ms
6,940 KB
testcase_31 AC 275 ms
6,940 KB
testcase_32 AC 278 ms
6,944 KB
testcase_33 AC 274 ms
6,944 KB
testcase_34 AC 299 ms
6,944 KB
testcase_35 AC 270 ms
6,944 KB
testcase_36 AC 260 ms
6,940 KB
testcase_37 AC 275 ms
6,944 KB
testcase_38 AC 270 ms
6,940 KB
testcase_39 AC 297 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <atcoder/all>
using ull = unsigned long long;
using namespace std;
using namespace atcoder;
using vst = vector<string>;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vP = vector<P>;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repp(i,k,n) for (ll i = k; i < n; i++)
#define per(i,s,e) for(ll i = s; i >= e; i--)
#define all(v) v.begin(),v.end()
#define yesno(a) a ? cout << "Yes" << '\n' : cout << "No" << '\n'
#define YESNO(a) a ? cout << "YES" << '\n' : cout << "NO" << '\n'
#define UNOmap unordered_map
#define UNOset unordered_set
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define debug(x) cerr << #x << " = " << x << '\n'

template<class... T>void in(T&... a){(cin >> ... >> a);}
template<class T, class... Ts>void out(const T& a, const Ts&... b){cout << a;((cout << ' ' <<  b), ...);cout << '\n';}
template<class T> void vin2(vector<T> &u,vector<T> &v){for(ll i = 0; i < (ll)v.size(); i++) in(u[i],v[i]);}
template<class T> void vin(vector<T> &v){for(ll i = 0; i < (ll)v.size(); i++)in(v[i]);}
template<class T> void vout(vector<T> &v){for(ll i = 0; i < (ll)v.size(); i++) cout << v[i] << ' ';cout << "\n";}

ll INF = 1152921504606846976;ll MOD =998244353; ll MOD1 =1000000007;
/* INF = 1LL << 60 */

#define sl(...) ll __VA_ARGS__; in(__VA_ARGS__)
 
using mint = modint998244353;
using mint1 = modint1000000007;
using mintn = modint;
using vm = vector<mint>;
using vvm = vector<vm>;

vl dx = {0,0,1,-1}, dy = {1,-1,0,0};
//----------------------------------------------



int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);cout<<fixed<<setprecision(15);
//==============================================

  ll H,W,K;
  in(H,W,K);
  vvl A(H,vl(W));
  rep(i,H){
    vin(A[i]);
  }
  
  auto f = [&](ll mid){
    
    vvl cost(H,vl(W,INF));
    deque<pair<ll,ll>> deq;
    
    deq.push_back(pair(0,0));
    cost[0][0] = A[0][0] < mid;
    
    
    while(deq.size()){
      auto[c,tmp] = deq.front();
      deq.pop_front();
      ll x = tmp/W;
      ll y = tmp%W;
      if(mid == 8){
        out(x,y,cost[x][y]);
      }
      if(c > cost[x][y])continue;
      rep(d,4){
        
        ll nx = x + dx[d];
        ll ny = y + dy[d];
        if(0 <= nx and nx < H and 0 <= ny and ny < W){
          ll d = 0;
          if(A[nx][ny] < mid){
            d++;
          }
          
          if(cost[x][y] + d >= cost[nx][ny]) continue;
          cost[nx][ny] = cost[x][y]+d;
          
          if(d == 0){
            deq.push_front(pair(cost[nx][ny],nx*W+ny));
          }
          else{
            deq.push_back(pair(cost[nx][ny],nx*W+ny));
          }
        }
      }
    }
    
    return cost[H-1][W-1] <= K;
      
  };
    
    
  ll ok = -1;
  ll ng = INF;
  while(ng-ok > 1){
    ll mid = (ok+ng)/2;
    if(f(mid)) ok = mid;
    else ng = mid;
  }
  
  
  if(ok >= 1000000000) ok = 1000000000;
  out(ok);
    
    
  
}
0