0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:08:47 +00:00

C - Belt Conveyor

https://atcoder.jp/contests/abc265/submissions/34231482
This commit is contained in:
Baoshuo Ren 2022-08-21 22:10:55 +08:00
parent ca73bb7c70
commit 1018034552
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

62
AtCoder/ABC265/C/C.cpp Normal file
View File

@ -0,0 +1,62 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 505;
int n, m;
char g[N][N];
bool vis[N][N];
void dfs(int x, int y, int lx, int ly) {
if (x <= 0 || x > n || y <= 0 || y > m) {
cout << lx << ' ' << ly << endl;
exit(0);
}
if (vis[x][y]) {
cout << -1 << endl;
exit(0);
}
vis[x][y] = true;
switch (g[x][y]) {
case 'U': {
dfs(x - 1, y, x, y);
break;
}
case 'D': {
dfs(x + 1, y, x, y);
break;
}
case 'L': {
dfs(x, y - 1, x, y);
break;
}
case 'R': {
dfs(x, y + 1, x, y);
break;
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> g[i][j];
}
}
dfs(1, 1, 1, 1);
return 0;
}