結果

問題 No.2855 Move on Grid
ユーザー mitanimitani
提出日時 2024-08-25 14:42:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 641 ms / 3,000 ms
コード長 1,524 bytes
コンパイル時間 4,447 ms
コンパイル使用メモリ 239,148 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 14:42:48
合計ジャッジ時間 22,591 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
6,812 KB
testcase_01 AC 186 ms
6,816 KB
testcase_02 AC 115 ms
6,940 KB
testcase_03 AC 77 ms
6,944 KB
testcase_04 AC 54 ms
6,940 KB
testcase_05 AC 118 ms
6,944 KB
testcase_06 AC 103 ms
6,940 KB
testcase_07 AC 11 ms
6,940 KB
testcase_08 AC 99 ms
6,944 KB
testcase_09 AC 38 ms
6,940 KB
testcase_10 AC 374 ms
6,940 KB
testcase_11 AC 348 ms
6,940 KB
testcase_12 AC 344 ms
6,940 KB
testcase_13 AC 352 ms
6,940 KB
testcase_14 AC 346 ms
6,944 KB
testcase_15 AC 377 ms
6,940 KB
testcase_16 AC 344 ms
6,940 KB
testcase_17 AC 345 ms
6,940 KB
testcase_18 AC 346 ms
6,940 KB
testcase_19 AC 373 ms
6,944 KB
testcase_20 AC 539 ms
6,944 KB
testcase_21 AC 588 ms
6,940 KB
testcase_22 AC 573 ms
6,940 KB
testcase_23 AC 531 ms
6,944 KB
testcase_24 AC 536 ms
6,944 KB
testcase_25 AC 630 ms
6,944 KB
testcase_26 AC 526 ms
6,940 KB
testcase_27 AC 601 ms
6,940 KB
testcase_28 AC 557 ms
6,940 KB
testcase_29 AC 581 ms
6,940 KB
testcase_30 AC 597 ms
6,944 KB
testcase_31 AC 630 ms
6,944 KB
testcase_32 AC 633 ms
6,940 KB
testcase_33 AC 641 ms
6,940 KB
testcase_34 AC 628 ms
6,940 KB
testcase_35 AC 585 ms
6,940 KB
testcase_36 AC 545 ms
6,944 KB
testcase_37 AC 607 ms
6,944 KB
testcase_38 AC 631 ms
6,940 KB
testcase_39 AC 602 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:60:30: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   60 |                         auto [c,p]=pq.top();pq.pop();
      |                              ^
main.cpp:61:30: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   61 |                         auto [x,y]=p;
      |                              ^

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(x) x.begin(), x.end()
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#include <atcoder/all>
using namespace atcoder;
//using mint=static_modint<998244353>;
using mint=static_modint<1000000007>;
////using mint=modint;
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

int inf=2147483647;
ll INF=9223372036854775807;
const ld PI=acos(-1);

void yn(bool f){
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return;
}

ll n,m;

bool in(int x,int y){
	if(x<0||n<=x)return false;
	if(y<0||m<=y)return false;
	return true;
}

vector<int> dx={1,-1,0,0};
vector<int> dy={0,0,1,-1};


int main(){
	ll k;cin>>n>>m>>k;
	vector<vector<ll>> a(n,vector<ll>(m));
	rep(i,n)rep(j,m)cin>>a[i][j];

	ll lb=1,ub=1000000000+1;
	priority_queue<pair<int,P>,vector<pair<int,P>>,greater<pair<int,P>>> pq;
	while(lb+1<ub){
		ll md=(lb+ub)/2;
		vector<vector<int>> cos(n,vector<int>(m,-1));

		
		if(a[0][0]<md){
			pq.push({1,{0,0}});
			cos[0][0]=1;
		}
		else{
			pq.push({0,{0,0}});
			cos[0][0]=0;
		}
		while(!pq.empty()){
			auto [c,p]=pq.top();pq.pop();
			auto [x,y]=p;
			rep(i,4){
				int nx=x+dx[i];
				int ny=y+dy[i];
				//cout<<nx<<" "<<ny<<endl;
				if(!in(nx,ny))continue;
				if(cos[nx][ny]!=-1)continue;

				int nc=c;
				if(a[nx][ny]<md)nc++;
				cos[nx][ny]=nc;
				pq.push({nc,{nx,ny}});
			}
		}

		if(cos[n-1][m-1]<=k)lb=md;
		else ub=md;
	}
	cout<<lb<<endl;
}
0