結果

問題 No.2855 Move on Grid
ユーザー 沙耶花
提出日時 2024-08-25 13:44:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,359 bytes
コンパイル時間 4,363 ms
コンパイル使用メモリ 261,072 KB
最終ジャッジ日時 2025-02-24 00:55:10
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 MLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

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];
	vector d(n,vector(m,vector<long long>(k+1,-Inf64)));
	using P = pair<long long,pair<pair<int,int>,int>>;
	priority_queue<P> q;
	d[0][0][0] = a[0][0];
	q.push({a[0][0],{{0,0},0}});
	if(k>0){
		d[0][0][1] = 1000000000;
		q.push({1000000000,{{0,0},1}});
	}
	vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1};
	while(!q.empty()){
		long long D = q.top().first;
		int x = q.top().second.first.first;
		int y = q.top().second.first.second;
		int z = q.top().second.second;
		
		q.pop();
		if(D>d[x][y][z])continue;
		rep(i,4){
			int nx = x+dx[i],ny = y+dy[i];
			if(nx<0||nx>=n||ny<0||ny>=m)continue;
			{
				long long nD = min(D, a[nx][ny]);
				if(nD>d[nx][ny][z]){
					d[nx][ny][z] = nD;
					q.push({nD,{{nx,ny},z}});
				}
			}
			if(z<k){
				long long nD = min(D , 1000000000LL);
				if(nD>d[nx][ny][z+1]){
					d[nx][ny][z+1] = nD;
					q.push({nD,{{nx,ny},z+1}});
				}
			}
		}
	}
	long long ans = -Inf64;
	rep(i,k+1)ans = max(ans,d[n-1][m-1][i]);
	cout<<ans<<endl;
    return 0;
}
0