Task: | Sokkelo |
Sender: | cowperso |
Submission time: | 2022-01-22 15:44:52 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 28 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 28 |
#2 | WRONG ANSWER | 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.69 s | 2 | details |
#5 | ACCEPTED | 0.46 s | 2 | details |
#6 | ACCEPTED | 0.38 s | 2 | details |
#7 | ACCEPTED | 0.01 s | 1, 2 | details |
#8 | ACCEPTED | 0.34 s | 2 | details |
#9 | ACCEPTED | 0.39 s | 2 | details |
#10 | ACCEPTED | 0.01 s | 1, 2 | details |
#11 | WRONG ANSWER | 0.43 s | 2 | details |
#12 | ACCEPTED | 0.01 s | 1, 2 | details |
#13 | ACCEPTED | 0.28 s | 2 | details |
#14 | ACCEPTED | 0.01 s | 1, 2 | details |
#15 | ACCEPTED | 0.28 s | 2 | details |
#16 | ACCEPTED | 0.01 s | 2 | details |
#17 | ACCEPTED | 0.02 s | 2 | details |
Compiler report
input/code.cpp: In function 'void haku(int32_t, int32_t)': input/code.cpp:59:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (y < 0 || y > n - 1 || x < 0 || x > m - 1) ~~^~~~~~~ input/code.cpp:59:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] if (y < 0 || y > n - 1 || x < 0 || x > m - 1) ~~^~~~~~~
Code
#include <iostream> #include <queue> #include <vector> bool kartta[1000][1000]; int64_t e[2000][2000]; bool z[2000][2000]; uint32_t n, m; std::vector<std::pair<std::pair<uint32_t, uint32_t>, int64_t>> naap(uint32_t y, uint32_t x) { std::vector<std::pair<std::pair<uint32_t, uint32_t>, int64_t>> res = {}; if (y >= 1000 || x >= 1000) { if (y != 1000) { res.push_back({{y - 1, x}, 100000}); } if (y != 1000 + n - 1) { res.push_back({{y + 1, x}, 100000}); } if (x != 1000) { res.push_back({{y, x - 1}, 100000}); } if (x != 1000 + m - 1) { res.push_back({{y, x + 1}, 100000}); } } else { if (y != 0 && !kartta[y - 1][x]) { res.push_back({{y - 1, x}, 1}); } if (y != 0 && kartta[y - 1][x]) { res.push_back({{y + 999, x + 1000}, 100000}); } if (y != n - 1 && !kartta[y + 1][x]) { res.push_back({{y + 1, x}, 1}); } if (y != n - 1 && kartta[y + 1][x]) { res.push_back({{y + 1001, x + 1000}, 100000}); } if (x != 0 && !kartta[y][x - 1]) { res.push_back({{y, x - 1}, 1}); } if (x != 0 && kartta[y][x - 1]) { res.push_back({{y + 1000, x + 999}, 100000}); } if (x != m - 1 && !kartta[y][x + 1]) { res.push_back({{y, x + 1}, 1}); } if (x != m - 1 && kartta[y][x + 1]) { res.push_back({{y + 1000, x + 1001}, 100000}); } } return res; } int64_t fres = INT64_MAX; bool z2[1000][1000]; void haku(int32_t y, int32_t x) { if (y < 0 || y > n - 1 || x < 0 || x > m - 1) return; if (kartta[y][x]) return; if (z2[y][x]) return; z2[y][x] = true; fres = std::min( fres, std::min(e[y][x], std::min(std::min(e[y - 1][x], e[y + 1][x]), std::min(e[y][x - 1], e[y][x + 1])))); fres = std::min( fres, std::min( e[y + 1000][x + 1000], std::min(std::min(e[y + 999][x + 1000], e[y + 1001][x + 1000]), std::min(e[y + 1000][x + 999], e[y + 1000][x + 1001])))); std::vector<std::pair<int32_t, int32_t>> diffs = { {1, 0}, {-1, 0}, {0, -1}, {0, 1}}; for (auto diff : diffs) { haku(y + diff.first, x + diff.second); } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> n >> m; uint32_t ax = 0, ay = 0; uint32_t bx = 0, by = 0; for (uint32_t i = 0; i < n; ++i) { for (uint32_t j = 0; j < m; ++j) { char c; std::cin >> c; switch (c) { case '#': kartta[i][j] = true; break; case 'A': ax = j; ay = i; break; case 'B': bx = j; by = i; break; } } } for (uint32_t i = 0; i < n; ++i) { for (uint32_t j = 0; j < m; ++j) { e[i][j] = INT64_C(1) << 60; e[i + 1000][j + 1000] = INT64_C(1) << 60; } } e[ay][ax] = 0; std::priority_queue<std::pair<int64_t, std::pair<uint32_t, uint32_t>>> q = {}; q.push({0, {ay, ax}}); while (!q.empty()) { uint32_t y = q.top().second.first; uint32_t x = q.top().second.second; q.pop(); if (z[y][x]) continue; z[y][x] = true; for (auto b : naap(y, x)) { if (e[y][x] + b.second < e[b.first.first][b.first.second]) { e[b.first.first][b.first.second] = e[y][x] + b.second; q.push({-e[b.first.first][b.first.second], b.first}); } } } haku(by, bx); if (fres >= 100000) { std::cout << fres / 100000 + 1 << '\n'; } else { std::cout << "1\n"; } }
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: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
2 |
Test 6
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
335 |
user output |
---|
335 |
Test 7
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #####.############## ###.....############ ##.......########### ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 8
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
436 |
user output |
---|
436 |
Test 9
Group: 2
Verdict: ACCEPTED
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
2 |
Test 10
Group: 1, 2
Verdict: ACCEPTED
input |
---|
20 20 #################### #B................## #################.## #################.## ... |
correct output |
---|
2 |
user output |
---|
2 |
Test 11
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 1000 ##############################... |
correct output |
---|
2 |
user output |
---|
3 |
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 |