結果
問題 | No.2411 Reverse Directions |
ユーザー | yutake2000 |
提出日時 | 2023-08-11 23:16:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,747 bytes |
コンパイル時間 | 2,799 ms |
コンパイル使用メモリ | 220,740 KB |
実行使用メモリ | 14,996 KB |
最終ジャッジ日時 | 2024-11-18 18:36:49 |
合計ジャッジ時間 | 45,112 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
10,496 KB |
testcase_01 | AC | 2 ms
10,112 KB |
testcase_02 | AC | 2 ms
10,496 KB |
testcase_03 | AC | 2 ms
9,344 KB |
testcase_04 | AC | 8 ms
10,496 KB |
testcase_05 | AC | 2 ms
8,320 KB |
testcase_06 | AC | 2 ms
10,496 KB |
testcase_07 | AC | 10 ms
11,648 KB |
testcase_08 | AC | 2 ms
9,344 KB |
testcase_09 | AC | 2 ms
10,496 KB |
testcase_10 | AC | 26 ms
14,996 KB |
testcase_11 | AC | 2 ms
8,576 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 3 ms
9,344 KB |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | AC | 2 ms
8,704 KB |
testcase_20 | TLE | - |
testcase_21 | AC | 4 ms
10,240 KB |
testcase_22 | TLE | - |
testcase_23 | AC | 4 ms
10,112 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | TLE | - |
testcase_27 | AC | 3 ms
5,248 KB |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | AC | 5 ms
10,240 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pll; typedef pair<ld, ld> Pdd; template<typename T> using MaxHeap = priority_queue<T>; template<typename T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define FORR(i, m, n) for(int i = m; i >= n; i--) #define INF (ll)1e17 #define ALL(v) v.begin(), v.end() #define SZ(x) ((ll)(x).size()) #define bit(n) (1LL<<(n)) #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define cauto const auto& #define cdebug if (debug_mode) cerr #define dump(x) if (debug_mode) cerr << #x << " = " << (x) << "\t"; #define SP << " " << #define TB << "\t" << #ifdef _LOCAL bool debug_mode = true; #else bool debug_mode = false; #endif int main() { ll H, W, K, L, R; cin >> H >> W >> K >> L >> R; vector<string> board(H); REP(i, H) cin >> board[i]; if ((R - L) % 2 == 0 || (H + W - K) % 2 != 0 || (K - (R-L+1)) < (H+W-2)) { cout << "No" << endl; return 0; } vector<vector<ll>> dist(H, vector<ll>(W, INF)); set<Pll> ps; deque<Pll> Q; Q.push_back({0, 0}); dist[0][0] = 0; ll dy[] = {0, 1, 0, -1}; ll dx[] = {1, 0, -1, 0}; while (!Q.empty()) { Pll p = Q.front(); Q.pop_front(); ll y = p.first, x = p.second; REP(k, 4) { ll ny = y + dy[k], nx = x + dx[k]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (board[ny][nx] == '#') continue; if (dist[ny][nx] <= dist[y][x]) continue; dist[ny][nx] = dist[y][x] + 1; Q.push_front({ny, nx}); if ((dist[y][x] - L) % 2 == 0 || dist[y][x] > L) continue; ll ny2 = y - dy[k], nx2 = x - dx[k]; if (ny2 < 0 || ny2 >= H || nx2 < 0 || nx2 >= W) continue; if (board[ny2][nx2] == '#') continue; ps.insert({y, x}); } } vector<vector<ll>> dist2(H, vector<ll>(W, INF)); deque<Pll> Q2; Q2.push_back({H-1, W-1}); dist2[H-1][W-1] = 0; while (!Q2.empty()) { Pll p = Q2.front(); Q2.pop_front(); ll y = p.first, x = p.second; REP(k, 4) { ll ny = y + dy[k], nx = x + dx[k]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (board[ny][nx] == '#') continue; if (dist2[ny][nx] <= dist2[y][x]) continue; dist2[ny][nx] = dist2[y][x] + 1; Q2.push_front({ny, nx}); } } for (auto p : ps) { ll y = p.first, x = p.second; cdebug << y SP x << endl; if (dist2[y][x] <= K - R) { string ans = ""; ll d = dist2[y][x]; // 経路復元 while (d > 0) { REP(k, 4) { ll ny = y + dy[k], nx = x + dx[k]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (board[ny][nx] == '#') continue; if (dist2[ny][nx] != d - 1) continue; ans += "RDLU"[k]; y = ny, x = nx; d--; break; } } reverse(ALL(ans)); y = p.first; x = p.second; REP(k, 2) { ll ny = y + dy[k], nx = x + dx[k]; ll ny2 = y - dy[k], nx2 = x - dx[k]; cdebug << ny SP nx SP ny2 SP nx2 << endl; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (ny2 < 0 || ny2 >= H || nx2 < 0 || nx2 >= W) continue; if (board[ny][nx] == '#') continue; if (board[ny2][nx2] == '#') continue; REP(i, (K-dist[y][x]-dist2[y][x])/2) { ans += "RDLU"[k]; ans += "RDLU"[k+2]; } break; } d = dist[y][x]; while (d > 0) { REP(k, 4) { ll ny = y + dy[k], nx = x + dx[k]; if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue; if (board[ny][nx] == '#') continue; if (dist[ny][nx] != d - 1) continue; ans += "LURD"[k]; y = ny, x = nx; d--; break; } } reverse(ALL(ans)); cout << "Yes" << endl; cout << ans << endl; return 0; } } cdebug << "unreachable" << endl; cout << "No" << endl; return 0; }