結果
問題 | No.2855 Move on Grid |
ユーザー | 👑 binap |
提出日時 | 2024-08-25 13:58:37 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,033 ms / 3,000 ms |
コード長 | 5,221 bytes |
コンパイル時間 | 4,737 ms |
コンパイル使用メモリ | 282,528 KB |
実行使用メモリ | 20,084 KB |
最終ジャッジ日時 | 2024-08-25 13:59:22 |
合計ジャッジ時間 | 35,084 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 190 ms
7,104 KB |
testcase_01 | AC | 244 ms
8,068 KB |
testcase_02 | AC | 163 ms
7,460 KB |
testcase_03 | AC | 111 ms
6,944 KB |
testcase_04 | AC | 82 ms
6,940 KB |
testcase_05 | AC | 173 ms
7,112 KB |
testcase_06 | AC | 225 ms
7,124 KB |
testcase_07 | AC | 19 ms
6,944 KB |
testcase_08 | AC | 127 ms
6,944 KB |
testcase_09 | AC | 82 ms
6,944 KB |
testcase_10 | AC | 831 ms
19,132 KB |
testcase_11 | AC | 892 ms
19,108 KB |
testcase_12 | AC | 851 ms
19,064 KB |
testcase_13 | AC | 896 ms
18,936 KB |
testcase_14 | AC | 839 ms
19,084 KB |
testcase_15 | AC | 823 ms
20,012 KB |
testcase_16 | AC | 844 ms
18,796 KB |
testcase_17 | AC | 837 ms
19,092 KB |
testcase_18 | AC | 879 ms
18,908 KB |
testcase_19 | AC | 832 ms
19,244 KB |
testcase_20 | AC | 950 ms
19,012 KB |
testcase_21 | AC | 918 ms
19,048 KB |
testcase_22 | AC | 886 ms
18,688 KB |
testcase_23 | AC | 887 ms
18,436 KB |
testcase_24 | AC | 853 ms
18,760 KB |
testcase_25 | AC | 960 ms
19,028 KB |
testcase_26 | AC | 884 ms
19,024 KB |
testcase_27 | AC | 907 ms
19,052 KB |
testcase_28 | AC | 873 ms
18,868 KB |
testcase_29 | AC | 885 ms
19,320 KB |
testcase_30 | AC | 1,023 ms
18,788 KB |
testcase_31 | AC | 940 ms
19,360 KB |
testcase_32 | AC | 998 ms
19,540 KB |
testcase_33 | AC | 954 ms
20,084 KB |
testcase_34 | AC | 959 ms
19,564 KB |
testcase_35 | AC | 968 ms
19,900 KB |
testcase_36 | AC | 1,033 ms
19,172 KB |
testcase_37 | AC | 932 ms
18,804 KB |
testcase_38 | AC | 1,006 ms
19,412 KB |
testcase_39 | AC | 964 ms
19,216 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using namespace atcoder; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; typedef long double ld; typedef pair<int, int> P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;} template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;} template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;} template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template<typename T> ostream& operator<<(ostream& os, const set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename T> ostream& operator<<(ostream& os, const unordered_set<T>& se){for(T x : se) os << x << " "; os << "\n"; return os;} template<typename S, auto op, auto e> ostream& operator<<(ostream& os, const atcoder::segtree<S, op, e>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename S, auto op, auto e, typename F, auto mapping, auto composition, auto id> ostream& operator<<(ostream& os, const atcoder::lazy_segtree<S, op, e, F, mapping, composition, id>& seg){int n = seg.max_right(0, [](S){return true;}); rep(i, n) os << seg.get(i) << (i == n - 1 ? "\n" : " "); return os;} template<typename T> void chmin(T& a, T b){a = min(a, b);} template<typename T> void chmax(T& a, T b){a = max(a, b);} const int INF = 1000000000; struct Edge_BFS01{ int from, to; int cost; Edge_BFS01(int from, int to, int cost) : from(from), to(to), cost(cost) {}; }; struct BFS01{ int n, m; vector<bool> initialized; vector<Edge_BFS01> E; vector<vector<int>> G; map<int, vector<int>> dist; map<int, vector<int>> idx; BFS01(int _n) : n(_n), m(0), initialized(n, false), G(n){} void add_edge(int from, int to, int cost){ assert(cost == 0 or cost == 1); Edge_BFS01 e(from, to, cost); E.push_back(e); G[from].emplace_back(m); m++; } void add_grid(int h, int w, vector<string> s){ assert(int(s.size()) == h); assert(int(s[0].size()) == w); rep(y, h){ rep(x, w - 1){ if(s[y][x] != '#' and s[y][x + 1] != '#'){ add_edge(y * w + x, y * w + (x + 1), 1); add_edge(y * w + (x + 1), y * w + x, 1); } } } rep(x, w){ rep(y, h - 1){ if(s[y][x] != '#' and s[y + 1][x] != '#'){ add_edge(y * w + x, (y + 1) * w + x, 1); add_edge((y + 1) * w + x, y * w + x, 1); } } } } void calc(int s){ initialized[s] = true; dist[s] = vector<int>(n, INF); idx[s] = vector<int>(n, -1); deque<tuple<int, int ,int>> de; de.emplace_back(0, s, -1); while(de.size()){ auto [cost, from, index] = de.front(); de.pop_front(); if(dist[s][from] <= cost) continue; dist[s][from] = cost; idx[s][from] = index; for(int index : G[from]){ int to = E[index].to; int cost_plus = E[index].cost; if(dist[s][to] <= cost + cost_plus) continue; if(cost_plus == 0) de.emplace_front(cost + cost_plus, to, index); if(cost_plus == 1) de.emplace_back(cost + cost_plus, to, index); } } } int farthest(int s){ if(!initialized[s]) calc(s); int idx = 0; rep(i, n) if(dist[s][i] > dist[s][idx]) idx = i; return idx; } int get_dist(int s, int t){ if(!initialized[s]) calc(s); return dist[s][t]; } vi restore(int s, int t){ if(!initialized[s]) calc(s); if(dist[s][t] == INF) return vi(0); vi res; while(idx[s][t] != -1){ auto e = E[idx[s][t]]; res.push_back(idx[s][t]); t = e.from; } reverse(res.begin(), res.end()); return res; } }; int main(){ int n, m, k; cin >> n >> m >> k; vector<vector<int>> a(n, vector<int>(m)); cin >> a; int ok = 0, ng = INF + 1; while(ng - ok > 1){ int mid = (ok + ng) / 2; BFS01 graph(n * m + 1); int sv = n * m; rep(y, n) rep(x, m - 1){ { int cost = 0; if(a[y][x + 1] < mid) cost = 1; graph.add_edge(y * m + x, y * m + (x + 1), cost); } { int cost = 0; if(a[y][x] < mid) cost = 1; graph.add_edge(y * m + (x + 1), y * m + x, cost); } } rep(y, n - 1) rep(x, m){ { int cost = 0; if(a[y + 1][x] < mid) cost = 1; graph.add_edge(y * m + x, (y + 1) * m + x, cost); } { int cost = 0; if(a[y][x] < mid) cost = 1; graph.add_edge((y + 1) * m + x, y * m + x, cost); } } { { int cost = 0; if(a[0][0] < mid) cost = 1; graph.add_edge(sv, 0, cost); } } int tot = graph.get_dist(sv, n * m - 1); if(tot <= k) ok = mid; else ng = mid; } cout << ok << "\n"; return 0; }