結果
| 問題 |
No.2855 Move on Grid
|
| コンテスト | |
| ユーザー |
shobonvip
|
| 提出日時 | 2024-08-25 13:47:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 209 ms / 3,000 ms |
| コード長 | 2,011 bytes |
| コンパイル時間 | 4,335 ms |
| コンパイル使用メモリ | 261,572 KB |
| 最終ジャッジ日時 | 2025-02-24 00:57:22 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 40 |
ソースコード
#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';
}
shobonvip