Task: | Sokkelo |
Sender: | lain |
Submission time: | 2022-01-22 16:06:06 +0200 |
Language: | C++ (C++17) |
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.11 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.03 s | 2 | details |
#14 | ACCEPTED | 0.01 s | 1, 2 | details |
#15 | ACCEPTED | 0.03 s | 2 | details |
#16 | ACCEPTED | 0.01 s | 2 | details |
#17 | ACCEPTED | 0.01 s | 2 | details |
Code
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define vc vector #define rep(i, a, b) for (int i = a; i < b; ++i) #define tra(a, x) for (auto &a : x) #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() template <typename... T> void get(T &...args) { ((cin >> args), ...); } template <typename... T> void pri(T &&...args) { ((cout << args << " "), ...); } template <typename... T> void pril(T &&...args) { ((cout << args << " "), ...); cout << '\n'; } using ll = long long; using vi = vc<int>; using vll = vc<ll>; using pi = pair<int, int>; const ll LINF = 1e18; const int INF = 1e9; const ll mod = 1e9 + 7; const int N = 1010; char grid[N][N]; int x[4] = {-1, 0, 1, 0}; int y[4] = {0, 1, 0, -1}; int n, m; vector<pair<pi, bool>> visited_points; pi a, b; void bfs(vector<vector<int>> &vis, pi start, bool isa) { queue<pi> q; q.push(start); vis[start.F][start.S] = 1; while (!q.empty()) { auto s = q.front(); q.pop(); rep(i, 0, 4) { pi ne = {s.F + x[i], s.S + y[i]}; if (ne.F < 0 || ne.F >= n || ne.S < 0 || ne.S >= m) continue; if (vis[ne.F][ne.S] == 1) continue; if (grid[ne.F][ne.S] == '#') continue; vis[ne.F][ne.S] = 1; visited_points.pb({ne, isa}); q.push(ne); } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); get(n, m); rep(i, 0, n) { rep(j, 0, m) { get(grid[i][j]); if (grid[i][j] == 'A') { a = {i, j}; } else if (grid[i][j] == 'B') { b = {i, j}; } } } vc<vi> vis_a(n, vi(m, 0)); bfs(vis_a, a, true); vc<vi> vis_b(n, vi(m, 0)); bfs(vis_b, b, false); int ans = INT_MAX; if (vis_a[b.F][b.S]) { pril(1); return 0; } else { for (int i = 0; i < sz(visited_points); ++i) { for (int j = i + 1; j < sz(visited_points); ++j) { if (visited_points[i].S != visited_points[j].S) { auto ap = visited_points[i].F; auto bp = visited_points[j].F; ans = min(ans, abs(ap.F - bp.F) + abs(ap.S - bp.S)); } } } } pril(ans); }
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 |