結果
問題 | No.2095 High Rise |
ユーザー | MasKoaTS |
提出日時 | 2022-10-07 22:20:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,002 ms / 2,000 ms |
コード長 | 2,832 bytes |
コンパイル時間 | 4,405 ms |
コンパイル使用メモリ | 273,736 KB |
実行使用メモリ | 28,268 KB |
最終ジャッジ日時 | 2024-06-12 19:10:35 |
合計ジャッジ時間 | 11,161 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 4 ms
6,944 KB |
testcase_13 | AC | 4 ms
6,944 KB |
testcase_14 | AC | 6 ms
6,940 KB |
testcase_15 | AC | 4 ms
6,944 KB |
testcase_16 | AC | 3 ms
6,940 KB |
testcase_17 | AC | 98 ms
6,940 KB |
testcase_18 | AC | 64 ms
6,940 KB |
testcase_19 | AC | 16 ms
6,944 KB |
testcase_20 | AC | 111 ms
6,948 KB |
testcase_21 | AC | 227 ms
9,728 KB |
testcase_22 | AC | 1,002 ms
28,268 KB |
testcase_23 | AC | 976 ms
28,268 KB |
testcase_24 | AC | 964 ms
28,268 KB |
testcase_25 | AC | 984 ms
28,268 KB |
testcase_26 | AC | 961 ms
28,264 KB |
ソースコード
#include <math.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define print(n) cout << (n) << endl #define fprint(n) cout << setprecision(16) << (n) << endl #define ceil_div(a, b) (((a) - 1) / (b) + 1) #define rep(i, l, n) for (int i = (l); i < (n); i++) #define itrep(itr, st) for (auto itr = st.begin(); itr != st.end(); itr++) #define ite(i, a) for (auto& i : a) #define all(x) x.begin(), x.end() #define lb(A, x) (lower_bound(all(A), x) - A.begin()) #define ub(A, x) (upper_bound(all(A), x) - A.begin()) using str = string; using ll = long long; using u32 = unsigned int; using u64 = unsigned long long; using Pair = pair<int, int>; using mint = modint1000000007; using Mint = modint998244353; template <class T> using V = vector<T>; template <class T> using VV = V<V<T> >; template <class T> using PQ = priority_queue<T, V<T>, greater<T> >; template <class T> using PQR = priority_queue<T>; template <class T> using BIT = fenwick_tree<T>; const ll INF = 4611686018427387903; const int inf = 2147483647; const ll mod = 1000000007; const ll MOD = 998244353; template <class T> inline V<T> getList(int n) { V<T> res(n); rep(i, 0, n) { cin >> res[i]; }return res; } template <class T> inline VV<T> getGrid(int m, int n) { VV<T> res(m, V<T>(n)); rep(i, 0, m) { res[i] = getList<T>(n); }return res; } template <class T> inline void prints(V<T>& vec) { if (vec.size() == 0)return; cout << vec[0]; rep(i, 1, vec.size()) { cout << ' ' << vec[i]; } cout << '\n'; } inline V<int> dtois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - '0'); } return vec; } inline V<int> atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'a'); } return vec; } inline V<int> Atois(string& s) { V<int> vec = {}; ite(e, s) { vec.push_back(e - 'A'); } return vec; } int main(void) { int n, m; cin >> n >> m; VV<ll> a = getGrid<ll>(n, m); VV<pair<ll, ll> > dp(n, V<pair<ll, ll> >(m, { INF,INF })); dp[0][0].first = 0; PQ<V<ll> > que = {}; que.push({ 0ll ,0ll,0ll,0ll }); while (que.empty() == false) { V<ll> vec = que.top(); que.pop(); ll c = vec[0], p = vec[1], q = vec[2], r = vec[3]; if ((r == 0 and c > dp[p][q].first) or (r == 1 and c > dp[p][q].second)) { continue; } if (p == n - 1) { print(c); break; } if (q > 0 and c < dp[p][q - 1].first) { dp[p][q - 1].first = c; que.push({ c, p, q - 1, 0 }); } if (q < m - 1 and c < dp[p][q + 1].first) { dp[p][q + 1].first = c; que.push({ c, p, q + 1, 0 }); } if (r == 0) { ll nc = c + a[p][q]; if (nc >= dp[p][q].second) { continue; } dp[p][q].second = nc; que.push({ nc,p,q,1 }); } else { ll nc = c + a[p + 1][q]; if (nc >= dp[p + 1][q].second) { continue; } dp[p + 1][q].second = nc; que.push({ nc,p + 1,q,1 }); } } return 0; }