用户输出
Yes
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#45868 | #1037. 膨胀的tyx | Accepted | 100 | 6336 ms | 62968 K | C++ 11 / 1.7 K | 233nihao | 2020-08-08 11:05:47 |
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
#define ll long long
int n, m;
queue<pair<int, int>> q;
int yes = 0;
int ifreach[2000][2000];
int x1[4] = { 0, 1, 0, -1 };
int y1[4] = { -1, 0, 1, 0 };
int g[2000][2000];
pair<int, int> from[2000][2000];
void bfs(int x, int y) {
pair<int, int> p;
int rx, ry;
int nx, ny;
q.push(make_pair(x, y));
while (!q.empty()) {
p = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
nx = p.first + x1[i];
ny = p.second + y1[i];
rx = (nx % n + n) % n;
ry = (ny % m + m) % m;
if (g[rx][ry] != 1) {
if (ifreach[rx][ry] == 0) {
q.push(make_pair(nx, ny));
from[rx][ry] = make_pair(nx, ny);
ifreach[rx][ry] = 1;
} else if (from[rx][ry] != make_pair(nx, ny)) {
yes = 1;
return;
}
}
}
}
}
int main() {
cin >> n >> m;
int startx, starty;
char c;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> c;
if (c == '#')
g[i][j] = 1;
else if (c == 'S') {
g[i][j] = 2;
startx = i;
starty = j;
from[i][j] = make_pair(i, j);
ifreach[i][j] = 1;
} else
g[i][j] = 3;
}
}
bfs(startx, starty);
if (yes == 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
用户输出
No
系统信息
Exited with return code 0
用户输出
Yes
系统信息
Exited with return code 0
用户输出
No
系统信息
Exited with return code 0
6 20
#.##.##.##.##.##.##.
#.##.##.##.##.##.##.
#.##.##.##.##.##.##.
S.#..#..#..#..#..#..
##..#.
<36 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
用户输出
No
系统信息
Exited with return code 0
2000 2000
S#########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
S.........................................................................................
<4001910 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
S.........................................................................................
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
S.........................................................................................
<4001910 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#S########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
##########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
##########################################################################################
<4001910 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
##########################################################################################
<4001910 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
#.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.##.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#.###.##.#.#.###..#.#.#...##....##...#..#.#......##.###.##.#..##...##...########.###..#.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#.###.##.#.#.###..#.#.#...##....##...#..#.#......##.###.##.#..##...##...########.###..#.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#.###.##.#.#.###..#.#.#...##....##...#..#.#......##.###.##.#..##...##...########.###..#.
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.######..##.###..##...#...#.#.#...#.######.#.#######.#...##.#########..#.##.#...##.###.#
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.######..##.###..##...#...#.#.#...#.######.#.#######.#...##.#########..#.##.#...##.###.#
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
#.######..##.###..##...#...#.#.#...#.######.#.#######.#...##.#########..#.##.#...##.###.#
<4003911 bytes omitted>
用户输出
No
系统信息
Exited with return code 0
2000 2000
.#...##...##....#.#....#.#.####..#.....###......##...#....##..##..#######...###.#.#.#...#
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
..##.....##..#.#..#..#.#..###....##.....#...#...........#.####......#..##.....###..#.#..#
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0
2000 2000
###....#..........#.#.......####..#.#.#.#.##...####..##..##............#..#.##..#.#...##.
<4003911 bytes omitted>
用户输出
Yes
系统信息
Exited with return code 0