| Task: | Sokkelo |
| Sender: | xenial |
| Submission time: | 2022-01-22 14:35:08 +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.62 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.02 s | 2 | details |
| #14 | ACCEPTED | 0.01 s | 1, 2 | details |
| #15 | ACCEPTED | 0.02 s | 2 | details |
| #16 | ACCEPTED | 0.01 s | 2 | details |
| #17 | ACCEPTED | 0.01 s | 2 | details |
Compiler report
input/code.cpp: In function 'void set_io(std::__cxx11::string)':
input/code.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen((filename + ".in").c_str(), "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen((filename + ".out").c_str(), "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define sz size
#define rsz resize
#define ii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
void set_io(string filename = "") {
ios::sync_with_stdio(0);
cin.tie(0);
if (filename != "") {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
}
int H, W, dx[] {-1, 0, 1 ,0}, dy[] {0, -1, 0, 1};
char grid[1005][1005];
ii j, k;
bool vis[1005][1005];
set<ii> visited;
int dist(ii a, ii b) {
return abs(a.fi - b.fi) + abs(a.se - b.se);
}
int main() {
set_io("");
cin >> H >> W;
for (int y = 0; y < H; y++)
for (int x = 0; x < W; x++) {
cin >> grid[x][y];
if (grid[x][y] == 'A') j = {x, y};
else if (grid[x][y] == 'B') k = {x, y};
}
queue<ii> q;
q.push(j);
int sd = INT_MAX;
ii cp;
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
if (vis[x][y]) continue;
vis[x][y] = true;
visited.insert({x, y});
for (int d = 0; d < 4; d++) {
int nx = x + dx[d],
ny = y + dy[d];
if (nx < 0 || nx >= W || ny < 0 || ny >= H || grid[nx][ny] != '.' ||
vis[nx][ny])
continue;
if (grid[nx][ny] == 'B') {
cout << 1 << endl;
return 0;
}
int cd = dist({nx, ny}, k);
if (cd < sd) {
sd = cd;
cp = ii(nx, ny);
}
q.push({nx, ny});
}
}
grid[cp.fi][cp.se] = 'A';
q = queue<ii>();
q.push(k);
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
if (vis[x][y]) continue;
vis[x][y] = true;
for (int d = 0; d < 4; d++) {
int nx = x + dx[d],
ny = y + dy[d];
if (nx < 0 || nx >= W || ny < 0 || ny >= H || grid[nx][ny] != '.' ||
vis[nx][ny])
continue;
int mindist = INT_MAX;
for (auto pos : visited) {
mindist = min(mindist, dist({nx, ny}, pos));
}
if (mindist < sd)
sd = mindist;
q.push({nx, ny});
}
}
cout << sd << endl;
}
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 |
