結果
問題 | No.2366 登校 |
ユーザー | t98slider |
提出日時 | 2023-06-30 23:01:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 68 ms / 4,000 ms |
コード長 | 4,186 bytes |
コンパイル時間 | 2,212 ms |
コンパイル使用メモリ | 187,092 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-06-12 07:51:35 |
合計ジャッジ時間 | 2,904 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 32 ms
6,944 KB |
testcase_13 | AC | 9 ms
6,940 KB |
testcase_14 | AC | 11 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,944 KB |
testcase_16 | AC | 1 ms
6,944 KB |
testcase_17 | AC | 20 ms
6,944 KB |
testcase_18 | AC | 18 ms
6,944 KB |
testcase_19 | AC | 27 ms
6,940 KB |
testcase_20 | AC | 8 ms
6,940 KB |
testcase_21 | AC | 7 ms
6,944 KB |
testcase_22 | AC | 18 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 4 ms
6,944 KB |
testcase_25 | AC | 67 ms
11,776 KB |
testcase_26 | AC | 68 ms
11,776 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> istream& operator >> (istream& is, vector<T>& vec) { for(T& x : vec) is >> x; return is; } template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } /*int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, k, t; cin >> h >> w >> k >> t; if(t >= h + w){ cout << 0 << '\n'; return 0; } vector<vector<ll>> C(h, vector<ll>(w)), D(h, vector<ll>(w)); for(int i = 0; i < k; i++){ int y, x, v1, v2; cin >> y >> x >> v1 >> v2; y--, x--; C[y][x] = v1; D[y][x] = v2; } const ll INF = 1ll << 60; //時間, y, x vector<vector<vector<ll>>> dptb(h + w, vector<vector<ll>>(h, vector<ll>(w, INF))); vector<rpriority_queue<tuple<ll, int, int>>> pqtb(h + w); dptb[0][0][0] = 0; pqtb[0].emplace(0, 0, 0); ll ans = INF; for(int hv = 0; hv < h + w; hv++){ auto &pq = pqtb[hv]; auto &dp = dptb[hv]; while(!pq.empty()){ ll d; int y, x; tie(d, y, x) = pq.top(); pq.pop(); if(d > dp[y][x]) continue; if(C[y][x] && hv + D[y][x] < h + w){ int hv2 = hv + D[y][x]; if(d - C[y][x] + 1 <= dptb[hv2][y][x]){ dptb[hv2][y][x] = d - C[y][x] + 1; pqtb[hv2].emplace(dptb[hv2][y][x], y, x); } } for(int i = 0; i < 4; i++){ int ny = y + (i == 0) - (i == 1); int nx = x + (i == 2) - (i == 3); if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue; if(d + 1 >= dp[ny][nx]) continue; dp[ny][nx] = d + 1; pq.emplace(d + 1, ny, nx); } } for(int y = 0; y < h; y++){ cerr << dp[y] << '\n'; } cerr << '\n'; if(dp[h - 1][w - 1] <= t){ cout << hv << '\n'; return 0; } } cout << -1 << '\n'; }*/ int main(){ ios::sync_with_stdio(false); cin.tie(0); int h, w, k, t; cin >> h >> w >> k >> t; if(t >= h + w - 2){ cout << 0 << '\n'; return 0; } vector<vector<ll>> C(h, vector<ll>(w)), D(h, vector<ll>(w)); for(int i = 0; i < k; i++){ int y, x, v1, v2; cin >> y >> x >> v1 >> v2; y--, x--; C[y][x] = v1; D[y][x] = v2; } int dec = h + w - 2 - t; const ll INF = 1ll << 60; //時間, y, x = 疲労 vector<vector<vector<ll>>> dp(dec, vector<vector<ll>>(h, vector<ll>(w, INF))); rpriority_queue<tuple<ll, ll, int, int>> pq; dp[0][0][0] = 0; pq.emplace(0, 0, 0, 0); ll ans = INF; while(!pq.empty()){ ll tim, d; int y, x; tie(d, tim, y, x) = pq.top(); pq.pop(); if(d > dp[tim][y][x]) continue; if(C[y][x] >= 2){ int nt = tim + C[y][x] - 1; if(nt < dec){ if(d + D[y][x] < dp[nt][y][x]){ dp[nt][y][x] = d + D[y][x]; pq.emplace(dp[nt][y][x], nt, y, x); } }else{ ans = min(ans, d + D[y][x]); } } for(int i = 0; i < 4; i++){ int ny = y + (i == 0) - (i == 1); int nx = x + (i == 2) - (i == 3); if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue; if(ny < y || nx < x){ int nt = tim - 2; if(nt < 0) continue; if(d >= dp[nt][ny][nx]) continue; dp[nt][ny][nx] = d; pq.emplace(d, nt, ny, nx); }else{ if(d >= dp[tim][ny][nx]) continue; dp[tim][ny][nx] = d; pq.emplace(d, tim, ny, nx); } } } if(ans == INF) ans = -1; cout << ans << '\n'; }