結果

問題 No.2855 Move on Grid
ユーザー 沙耶花沙耶花
提出日時 2024-08-25 13:46:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 306 ms / 3,000 ms
コード長 1,101 bytes
コンパイル時間 4,865 ms
コンパイル使用メモリ 269,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 13:47:14
合計ジャッジ時間 14,635 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
6,812 KB
testcase_01 AC 97 ms
6,816 KB
testcase_02 AC 57 ms
6,940 KB
testcase_03 AC 46 ms
6,944 KB
testcase_04 AC 32 ms
6,944 KB
testcase_05 AC 68 ms
6,940 KB
testcase_06 AC 66 ms
6,940 KB
testcase_07 AC 9 ms
6,944 KB
testcase_08 AC 56 ms
6,940 KB
testcase_09 AC 27 ms
6,940 KB
testcase_10 AC 214 ms
6,940 KB
testcase_11 AC 214 ms
6,940 KB
testcase_12 AC 214 ms
6,944 KB
testcase_13 AC 216 ms
6,940 KB
testcase_14 AC 212 ms
6,940 KB
testcase_15 AC 216 ms
6,944 KB
testcase_16 AC 218 ms
6,940 KB
testcase_17 AC 224 ms
6,944 KB
testcase_18 AC 213 ms
6,940 KB
testcase_19 AC 216 ms
6,940 KB
testcase_20 AC 303 ms
6,944 KB
testcase_21 AC 299 ms
6,940 KB
testcase_22 AC 302 ms
6,940 KB
testcase_23 AC 303 ms
6,944 KB
testcase_24 AC 302 ms
6,944 KB
testcase_25 AC 293 ms
6,940 KB
testcase_26 AC 304 ms
6,940 KB
testcase_27 AC 298 ms
6,940 KB
testcase_28 AC 293 ms
6,944 KB
testcase_29 AC 306 ms
6,944 KB
testcase_30 AC 298 ms
6,944 KB
testcase_31 AC 295 ms
6,944 KB
testcase_32 AC 295 ms
6,944 KB
testcase_33 AC 294 ms
6,940 KB
testcase_34 AC 290 ms
6,944 KB
testcase_35 AC 281 ms
6,940 KB
testcase_36 AC 257 ms
6,944 KB
testcase_37 AC 295 ms
6,944 KB
testcase_38 AC 287 ms
6,940 KB
testcase_39 AC 292 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	
	int n,m,k;
	cin>>n>>m>>k;
	k = min(k, n+m);
	vector a(n,vector<long long>(m));
	rep(i,n)rep(j,m)cin>>a[i][j];
	int ok = 0,ng = 1000000001;
	while(ng-ok>1){
		int mid  =(ok+ng)/2;
		vector d(n,vector<int>(m,Inf32));
		deque<pair<int,int>> D;
		if(a[0][0]>=mid)d[0][0] = 0;
		else d[0][0] = 1;
		D.push_back({0,0});
		while(D.size()>0){
			int x = D.front().first;
			int y = D.front().second;
			D.pop_front();
			vector<int> dx = {1,-1,0,0},dy  = {0,0,1,-1};
			rep(i,4){
				int nx = x+dx[i];
				int ny = y+dy[i];
				if(nx<0||nx>=n||ny<0||ny>=m)continue;
				int cost = d[x][y];
				if(a[nx][ny]<mid)cost++;
				if(cost<d[nx][ny]){
					d[nx][ny] = cost;
					if(a[nx][ny]>=mid)D.push_front({nx,ny});
					else D.push_back({nx,ny});
				}
			}
		}
		if(d[n-1][m-1] <= k)ok = mid;
		else ng = mid;
	}
	cout<<ok<<endl;
    return 0;
}
0