Task: | Sokkelo |
Sender: | xyrj |
Submission time: | 2022-01-22 13:55:59 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 28 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 28 |
#2 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2 | details |
#2 | ACCEPTED | 0.01 s | 1, 2 | details |
#3 | ACCEPTED | 0.01 s | 1, 2 | details |
#4 | ACCEPTED | 0.76 s | 2 | details |
#5 | TIME LIMIT EXCEEDED | -- | 2 | details |
#6 | TIME LIMIT EXCEEDED | -- | 2 | details |
#7 | ACCEPTED | 0.01 s | 1, 2 | details |
#8 | TIME LIMIT EXCEEDED | -- | 2 | details |
#9 | TIME LIMIT EXCEEDED | -- | 2 | details |
#10 | ACCEPTED | 0.01 s | 1, 2 | details |
#11 | TIME LIMIT EXCEEDED | -- | 2 | details |
#12 | ACCEPTED | 0.01 s | 1, 2 | details |
#13 | ACCEPTED | 0.05 s | 2 | details |
#14 | ACCEPTED | 0.01 s | 1, 2 | details |
#15 | ACCEPTED | 0.05 s | 2 | details |
#16 | ACCEPTED | 0.01 s | 2 | details |
#17 | ACCEPTED | 0.01 s | 2 | details |
Code
#include <iostream> #include <vector> #include <set> using namespace std; char kartta[1000][1001]{}; void paasy(set<pair<int, int>> &p, int n, int m, int y, int x) { if (p.find({y, x}) != p.end()) return; if (y < 0 || x < 0 || y >= n || x >= m) return; if (kartta[y][x] == '#') return; p.insert({y, x}); paasy(p, n, m, y + 1, x); paasy(p, n, m, y - 1, x); paasy(p, n, m, y, x - 1); paasy(p, n, m, y, x + 1); }; int main() { int n, m; cin >> n >> m; pair<int, int> A; pair<int, int> B; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { cin >> kartta[i][j]; if (kartta[i][j] == 'A') A = {i, j}; if (kartta[i][j] == 'B') B = {i, j}; } set<pair<int, int>> An; paasy(An, n, m, A.first, A.second); if (An.find({B.first, B.second}) != An.end()) { cout << "1"; return 0; } set<pair<int, int>> Bn; paasy(Bn, n, m, B.first, B.second); int tulos = 1e9; for (pair<int, int> a : An) for (pair<int, int> b : Bn) tulos = min(tulos, abs(a.first - b.first) + abs(a.second - b.second)); cout << tulos; }
Test details
Test 1
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
1 |
user output |
---|
1 |
Test 2
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 3
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #A.................# #..................# #..................# ... |
correct output |
---|
9 |
user output |
---|
9 |
Test 4
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
1 |
Test 5
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 6
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ##############################... |
correct output |
---|
335 |
user output |
---|
(empty) |
Test 7
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #####.############## ###.....############ ##.......########### ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 8
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ##############################... |
correct output |
---|
436 |
user output |
---|
(empty) |
Test 9
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 10
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #B................## #################.## #################.## ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 11
Group: 2
Verdict: TIME LIMIT EXCEEDED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
(empty) |
Test 12
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 13
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
2 |
Test 14
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### ##########A######### ##########.######### ##########.######### ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 15
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
502 |
user output |
---|
502 |
Test 16
Group: 2
Verdict: ACCEPTED
input |
---|
3 1000 ##############################... |
correct output |
---|
1 |
user output |
---|
1 |
Test 17
Group: 2
Verdict: ACCEPTED
input |
---|
1000 3 ### #A# #.# #.# ... |
correct output |
---|
1 |
user output |
---|
1 |