結果

問題 No.2855 Move on Grid
ユーザー shobonvipshobonvip
提出日時 2024-08-25 13:47:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 204 ms / 3,000 ms
コード長 2,011 bytes
コンパイル時間 4,747 ms
コンパイル使用メモリ 272,608 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-25 13:47:38
合計ジャッジ時間 10,874 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
6,812 KB
testcase_01 AC 58 ms
6,940 KB
testcase_02 AC 32 ms
6,944 KB
testcase_03 AC 28 ms
6,940 KB
testcase_04 AC 22 ms
6,940 KB
testcase_05 AC 41 ms
6,940 KB
testcase_06 AC 37 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 33 ms
6,944 KB
testcase_09 AC 17 ms
6,944 KB
testcase_10 AC 113 ms
6,944 KB
testcase_11 AC 122 ms
6,944 KB
testcase_12 AC 111 ms
6,940 KB
testcase_13 AC 110 ms
6,940 KB
testcase_14 AC 112 ms
6,940 KB
testcase_15 AC 116 ms
6,940 KB
testcase_16 AC 113 ms
6,940 KB
testcase_17 AC 129 ms
6,940 KB
testcase_18 AC 113 ms
6,940 KB
testcase_19 AC 117 ms
6,940 KB
testcase_20 AC 181 ms
6,944 KB
testcase_21 AC 204 ms
6,944 KB
testcase_22 AC 178 ms
6,940 KB
testcase_23 AC 180 ms
6,940 KB
testcase_24 AC 202 ms
6,944 KB
testcase_25 AC 179 ms
6,940 KB
testcase_26 AC 180 ms
6,940 KB
testcase_27 AC 198 ms
6,940 KB
testcase_28 AC 176 ms
6,944 KB
testcase_29 AC 183 ms
6,944 KB
testcase_30 AC 180 ms
6,940 KB
testcase_31 AC 199 ms
6,944 KB
testcase_32 AC 185 ms
6,940 KB
testcase_33 AC 178 ms
6,940 KB
testcase_34 AC 178 ms
6,940 KB
testcase_35 AC 193 ms
6,940 KB
testcase_36 AC 146 ms
6,944 KB
testcase_37 AC 203 ms
6,944 KB
testcase_38 AC 179 ms
6,940 KB
testcase_39 AC 180 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

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

	auto check = [&](ll t) -> bool {
		vector d(n, vector<ll>(m,1e18));
		vector seen(n, vector<bool>(m));
		d[0][0] = (a[0][0] < t);
		deque<pair<int,int>> mada;
		mada.push_back(pair(0, 0));
		while(!mada.empty()){
			auto [i,j] = mada.front();
			mada.pop_front();
			if(seen[i][j]) continue;
			seen[i][j] = 1;
			for (auto[x,y]: {
				pair(i+1, j),
				pair(i-1, j),
				pair(i, j-1),
				pair(i, j+1)
			}){
				if(!(0 <= x && x < n)) continue;
				if(!(0 <= y && y < m)) continue;
				if (a[x][y] < t) {
					if (chmin(d[x][y], d[i][j] + 1)){
						mada.push_back(pair(x, y));
					}
				}else{
					if (chmin(d[x][y], d[i][j])){
						mada.push_front(pair(x,y));
					}
				}
			}
		}
		return d[n-1][m-1] <= k;
	};

	ll ub = 1e9 + 1;
	ll lb = 0;
	while(ub-lb > 1){
		ll t = (ub + lb) / 2;
		if (check(t)) lb = t;
		else ub = t;
	}

	cout << lb << '\n';
}

0