提出 #74854686
ソースコード 拡げる
#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
int main() {
fastio; int H, W; cin >> H >> W;
vector<string> v(H);
for (auto &i : v) cin >> i;
int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 };
auto chk = [&](int x, int y) { return (0 <= x && x < H && 0 <= y && y < W && v[x][y] != '#'); };
vector<int> adj(H*W);
int sx, sy, ex, ey;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (v[i][j] == 'S') sx = i, sy = j;
if (v[i][j] == 'G') ex = i, ey = j;
}
}
vector<vector<vector<bool>>> vis(H, vector<vector<bool>>(W, vector<bool>(4)));
string ans;
auto dfs = [&](auto dfs, int x, int y, int dir) -> bool {
vis[x][y][dir] = 1;
if (x == ex && y == ey) return true;
for (int d = 0; d < 4; d++) {
int nx = x+dx[d], ny = y+dy[d];
if (!chk(nx, ny) || vis[nx][ny][d]) continue;
if (v[x][y] == 'o' && d != dir) continue;
if (v[x][y] == 'x' && d == dir) continue;
ans += "DRUL"[d];
if (dfs(dfs, nx, ny, d)) return true;
ans.pop_back();
}
return false;
};
if (dfs(dfs, sx, sy, 0)) cout << "Yes\n" << ans << "\n";
else cout << "No\n";
return 0;
}
提出情報
提出日時
2026-04-11 21:20:23+0900
問題
D - Go Straight
ユーザ
Lov34ever
言語
C++23 (GCC 15.2.0)
得点
425
コード長
1559 Byte
結果
AC
実行時間
839 ms
メモリ
953904 KiB
コンパイルエラー
./Main.cpp: In function 'main':
./Main.cpp:40:12: warning: 'sx' may be used uninitialized [-Wmaybe-uninitialized]
40 | if (dfs(dfs, sx, sy, 0)) cout << "Yes\n" << ans << "\n";
| ^
./Main.cpp:17:9: note: 'sx' was declared here
17 | int sx, sy, ex, ey;
| ^
./Main.cpp:40:12: warning: 'sy' may be used uninitialized [-Wmaybe-uninitialized]
40 | if (dfs(dfs, sx, sy, 0)) cout << "Yes\n" << ans << "\n";
| ^
./Main.cpp:17:13: note: 'sy' was declared here
17 | int sx, sy, ex, ey;
| ^
ジャッジ結果
セット名
Sample
All
得点 / 配点
0 / 0
425 / 425
結果
セット名
テストケース
Sample
example_00.txt, example_01.txt, example_02.txt
All
example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt
ケース名
結果
実行時間
メモリ
example_00.txt
AC
1 ms
3572 KiB
example_01.txt
AC
1 ms
3420 KiB
example_02.txt
AC
1 ms
3532 KiB
hand_00.txt
AC
67 ms
75320 KiB
hand_01.txt
AC
66 ms
74960 KiB
hand_02.txt
AC
784 ms
953904 KiB
hand_03.txt
AC
839 ms
952048 KiB
hand_04.txt
AC
2 ms
3564 KiB
hand_05.txt
AC
631 ms
951220 KiB
hand_06.txt
AC
357 ms
512364 KiB
hand_07.txt
AC
632 ms
953032 KiB
hand_08.txt
AC
66 ms
74884 KiB
hand_09.txt
AC
1 ms
3504 KiB
random_00.txt
AC
64 ms
71312 KiB
random_01.txt
AC
271 ms
206632 KiB
random_02.txt
AC
116 ms
116636 KiB
random_03.txt
AC
63 ms
70352 KiB
random_04.txt
AC
145 ms
138468 KiB
random_05.txt
AC
150 ms
90640 KiB
random_06.txt
AC
64 ms
72144 KiB
random_07.txt
AC
63 ms
71292 KiB
random_08.txt
AC
109 ms
87616 KiB
random_09.txt
AC
138 ms
104400 KiB
random_10.txt
AC
127 ms
95032 KiB
random_11.txt
AC
148 ms
89292 KiB
random_12.txt
AC
118 ms
94344 KiB
random_13.txt
AC
54 ms
65684 KiB
random_14.txt
AC
105 ms
90316 KiB
random_15.txt
AC
58 ms
65660 KiB
random_16.txt
AC
61 ms
68368 KiB
random_17.txt
AC
57 ms
63612 KiB
random_18.txt
AC
57 ms
64932 KiB
random_19.txt
AC
64 ms
72700 KiB
random_20.txt
AC
57 ms
65300 KiB
random_21.txt
AC
60 ms
68884 KiB
random_22.txt
AC
58 ms
66124 KiB
random_23.txt
AC
64 ms
72780 KiB
random_24.txt
AC
74 ms
79436 KiB
random_25.txt
AC
62 ms
68688 KiB
random_26.txt
AC
58 ms
64972 KiB
random_27.txt
AC
243 ms
265728 KiB
random_28.txt
AC
61 ms
68688 KiB
random_29.txt
AC
66 ms
70932 KiB
random_30.txt
AC
136 ms
102932 KiB
random_31.txt
AC
93 ms
98384 KiB
random_32.txt
AC
67 ms
71432 KiB