QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#740054 | #8995. Snake | ucup-team004 | AC ✓ | 35ms | 7000kb | C++23 | 2.6kb | 2024-11-13 00:41:15 | 2024-11-13 00:41:18 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
using u128 = unsigned __int128;
constexpr int dx[] = {1, 0, -1, 0};
constexpr int dy[] = {0, 1, 0, -1};
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int r, c;
std::cin >> r >> c;
std::vector<std::string> s(r);
for (int i = 0; i < r; i++) {
std::cin >> s[i];
}
int len = 0;
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (s[i][j] != '.' && s[i][j] != 'A') {
len++;
}
}
}
std::vector<int> a(len);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (s[i][j] != '.' && s[i][j] != 'A') {
char ch = s[i][j];
int x = std::isdigit(ch) ? ch - '0' : ch - 'a' + 10;
a[x] = i * c + j;
}
}
}
std::queue<std::vector<int>> q;
q.push(a);
while (!q.empty()) {
auto a = q.front();
q.pop();
std::vector b(r, std::vector<bool>(c)), vis(r, std::vector<bool>(c));
for (auto i : a) {
int x = i / c;
int y = i % c;
b[x][y] = true;
}
int x = a[0] / c, y = a[0] % c;
{
std::queue<std::array<int, 2>> q;
vis[x][y] = true;
q.push({x, y});
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
if (s[x][y] == 'A') {
std::cout << "1\n";
return 0;
}
for (int k = 0; k < 4; k++) {
int nx = x + dx[k];
int ny = y + dy[k];
if (0 <= nx && nx < r && 0 <= ny && ny < c && !b[nx][ny] && !vis[nx][ny]) {
vis[nx][ny] = true;
q.push({nx, ny});
}
}
}
}
for (int k = 0; k < 4; k++) {
int nx = x + dx[k];
int ny = y + dy[k];
if (0 <= nx && nx < r && 0 <= ny && ny < c && std::find(a.begin(), a.begin() + std::max(2, len - 1), nx * c + ny) == a.begin() + std::max(2, len - 1)) {
auto b = a;
b.pop_back();
b.insert(b.begin(), nx * c + ny);
q.push(b);
}
}
}
std::cout << "0\n";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3600kb
input:
2 1 0 A
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
5 8 ......01 ....98.2 ...A.7.3 .....654 ........
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
5 4 ...A .... 6789 5432 ..01
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 5 ....A ..... 678.. 54321 ....0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
4 4 567A 4389 12ba 0dc.
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 1 0 1 A
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
10 10 A......... .......... .......... .......... .......... .......... .......... .......... .......... .........0
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
10 10 A......... .......... .......... .......... .......... ....98.... .....76... ......54.. .......32. ........10
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 10 A10.......
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
10 10 A......... .......... .......... .......... .......... .......... .......... ......5678 ......4.09 ......321.
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
10 10 A......... .......... .......... .......... .......... .......... .......... .......456 .......307 .......218
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
10 10 .......... .......... .......... .......... 9......... 8......... 7......... 6......... 5432...... A.01......
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 10 A......... .......... .......... .......... ....9..... ....8..... ....7..... ....6..... 12345..... 0.........
output:
1
result:
ok single line: '1'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
4 5 6789A 54321 ....0 .....
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
10 10 A......... .......... .......... .......... .......... .......... .......... .....fedcb 123456789a 0.........
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
10 10 .......... .......... .01....... ..23...... ...45..... ....67.... .....89... ......abA. .......cd. ........ef
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
10 10 .......... .......... .......... .......... .......... .......... .234567... A10...8... fedcba9... ..........
output:
0
result:
ok single line: '0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
10 10 .......... .......... .......... ..43210... ..5edc.... ..6fAb.... ..789a.... .......... .......... ..........
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
10 3 ... ... ... ... 210 345 876 9ab edc fA.
output:
0
result:
ok single line: '0'
Test #20:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
10 3 ... ... ... ... 210 345 876 9ab .dc ..A
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
10 3 ... ... ... ... 210 345 876 9ab .dc .eA
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
8 7 ..32... 6541... 7..0... 8..f... 9cde... ab..... .A..... .......
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
7 6 ..1234 ..0765 ...89. ....a. ....bA ...dc. ..fe..
output:
1
result:
ok single line: '1'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3760kb
input:
8 8 ef...... d....... cba..... ..9..... ..8..... ..76.0.. ...521.. A..43...
output:
1
result:
ok single line: '1'
Test #25:
score: 0
Accepted
time: 4ms
memory: 3920kb
input:
8 7 ...678. .A.5.9a 1234dcb 0...ef. ....... ....... ....... .......
output:
1
result:
ok single line: '1'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
8 6 ...... ...... ....f. 0.45ed 12367c ....8b ....9a A.....
output:
1
result:
ok single line: '1'
Test #27:
score: 0
Accepted
time: 35ms
memory: 7000kb
input:
8 6 A10... 32.... 4..... 5..... 6.cdef 7.b... 89a... ......
output:
1
result:
ok single line: '1'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
8 5 ..... ..... ..... ..... 23456 10987 ..abc .Afed
output:
1
result:
ok single line: '1'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
8 8 dA...... c....... ba98.... ...7.... ...6.... ...5.... ...43... ....210.
output:
1
result:
ok single line: '1'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
10 9 ......... ......... ......... A........ ......... ......... ..bcdef.. ..a9..... ...8...01 ...765432
output:
1
result:
ok single line: '1'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
10 9 ...10.... ...23.... ...54.... ...69abcd ...78...e ........f ......... ......... .A....... .........
output:
1
result:
ok single line: '1'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
5 2 A5 34 2. 1. 0.
output:
1
result:
ok single line: '1'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
1 7 ...01A.
output:
0
result:
ok single line: '0'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
10 10 ...10..... ...23..... ....478... ....569a.. .......bc. ........de .........f .......... .......... .A........
output:
1
result:
ok single line: '1'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
8 8 .......A cdef.... ba9..... .78..... .6...... 45...... 3....... 210.....
output:
1
result:
ok single line: '1'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
9 3 .34 .25 .10 ..A ... ... ... ... ...
output:
1
result:
ok single line: '1'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
6 4 .... .... 3456 2.87 109a Adcb
output:
1
result:
ok single line: '1'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 10 .........A .......... ..fe...... 678d...... 5.9c...... 43ab...... .2........ .10....... .......... ..........
output:
1
result:
ok single line: '1'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
9 8 ........ ........ 0....... 12...... .3...... .4589cd. ..67abe. ......f. .......A
output:
1
result:
ok single line: '1'
Test #40:
score: 0
Accepted
time: 5ms
memory: 3972kb
input:
4 9 ....cba76 ....d.985 ....ef.34 .....012A
output:
1
result:
ok single line: '1'
Test #41:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
10 5 ..... ..A.. ..... ....f 89abe 701cd 652.. .43.. ..... .....
output:
0
result:
ok single line: '0'
Test #42:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
10 10 .......... ......0... ......1... ......2... dc..543... eba.6..... f.987..... .......... .......... A.........
output:
1
result:
ok single line: '1'
Test #43:
score: 0
Accepted
time: 12ms
memory: 5268kb
input:
6 8 A456789. 23..eda. 1...fcb. 0....... ........ ........
output:
1
result:
ok single line: '1'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
5 2 .. .A 10 23 54
output:
1
result:
ok single line: '1'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
9 9 ......... ......... .21....A. 430...... 56....... a7....... 98....... ......... .........
output:
1
result:
ok single line: '1'
Test #46:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
8 3 45A 30. 21. ... ... ... ... ...
output:
1
result:
ok single line: '1'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
7 2 76 45 32 01 A. .. ..
output:
1
result:
ok single line: '1'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
9 4 .... .... f... e... d65. c74. b83A a92. .01.
output:
0
result:
ok single line: '0'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
6 6 ...... ....10 ..A32. ...456 ...ba7 ..dc98
output:
1
result:
ok single line: '1'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
5 4 .014 ..23 .... .... ..A.
output:
1
result:
ok single line: '1'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 6 234..A 1..... 0..... ......
output:
1
result:
ok single line: '1'
Test #52:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
7 8 234..... 1A5..... 0.67abc. ...89... ........ ........ ........
output:
1
result:
ok single line: '1'
Test #53:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 4 ...0 ...1 ...2 ..A.
output:
1
result:
ok single line: '1'
Test #54:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
8 6 ...... ...... A..... ...... ...... .b.32. 9a541. 876.0.
output:
1
result:
ok single line: '1'
Test #55:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
5 7 ....... ....... ....... ...A... .....01
output:
1
result:
ok single line: '1'
Test #56:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
5 7 A6501.. .7432.. 98..... ab..... .......
output:
0
result:
ok single line: '0'