| Task: | Suunnistus |
| Sender: | Verlet |
| Submission time: | 2025-01-18 21:05:08 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 31 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 31 |
| #2 | TIME LIMIT EXCEEDED | 0 |
| #3 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | 3 | details |
| #2 | ACCEPTED | 0.11 s | 1, 2, 3 | details |
| #3 | ACCEPTED | 0.08 s | 1, 2, 3 | details |
| #4 | ACCEPTED | 0.02 s | 1, 2, 3 | details |
| #5 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
| #6 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
| #7 | ACCEPTED | 0.83 s | 2, 3 | details |
| #8 | TIME LIMIT EXCEEDED | -- | 2, 3 | details |
| #9 | ACCEPTED | 0.02 s | 2, 3 | details |
| #10 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #12 | ACCEPTED | 0.02 s | 3 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 3 | details |
| #14 | ACCEPTED | 0.15 s | 2, 3 | details |
| #15 | ACCEPTED | 0.01 s | 3 | details |
| #16 | ACCEPTED | 0.01 s | 3 | details |
| #17 | ACCEPTED | 0.17 s | 2, 3 | details |
Compiler report
input/code.cpp: In function 'void bfs(std::vector<std::pair<int, std::pair<int, int> > >&, std::vector<std::pair<int, std::pair<int, int> > >&, char)':
input/code.cpp:52:20: warning: array subscript has type 'char' [-Wchar-subscripts]
52 | if (++c >= p[target]) break;
| ^~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:86:30: warning: array subscript has type 'char' [-Wchar-subscripts]
86 | if (c >= 48 && c < 58) p[c]++;
| ^Code
#include <bits/stdc++.h>
#define N 502
#define F first
#define S second
#define pb push_back
using namespace std;
typedef pair<int, int> ip;
typedef pair<int, ip> Node;
int p[64];
char m[N][N];
char v[N][N];
void reset()
{
for (int y = 0; y < N; y++)
for (int x = 0; x < N; x++)
{
v[x][y] = false;
}
}
void bfs(vector<Node> & start, vector<Node> & end, char target)
{
priority_queue<Node, vector<Node>, greater<Node>> q;
for (Node n : start) q.push(n);
int c = 0;
while (q.size())
{
Node n = q.top(); q.pop();
int d = n.F;
int x = n.S.F;
int y = n.S.S;
if (v[x][y] || m[x][y] == '#') continue;
v[x][y] = true;
if (m[x][y] == target)
{
end.pb(n);
if (++c >= p[target]) break;
}
q.push({d+1, {x+1, y}});
q.push({d+1, {x-1, y}});
q.push({d+1, {x, y+1}});
q.push({d+1, {x, y-1}});
}
}
int main()
{
int w, h, k; cin >> h >> w >> k;
for (int y = 0; y < N; y++)
for (int x = 0; x < N; x++)
{
m[x][y] = '#';
}
ip s, e;
// cout << "Width: " << w << endl;
// cout << "Height: " << h << endl;
for (int y = 1; y <= h; y++)
for (int x = 1; x <= w; x++)
{
char c; cin >> c;
if (c != '#') m[x][y] = c;
if (c == 'S') s = {x, y};
if (c == 'E') e = {x, y};
if (c >= 48 && c < 58) p[c]++;
}
// cout << "Start: " << s.F << " " << s.S << endl;
// cout << "End: " << e.F << " " << e.S << endl;
// for (int y = 0; y <= h + 1; y++)
// {
// for (int x = 0; x <= w + 1; x++)
// {
// cout << m[x][y] << " ";
// }
// cout << endl;
// }
vector<Node> start, end;
start.pb({0, s});
for (char c = '1'; c < '1' + k; c++)
{
bfs(start, end, c);
reset();
if (end.size() == 0)
{
cout << -1 << endl;
exit(0);
}
start.clear();
for (Node n : end) start.pb(n);
end.clear();
}
bfs(start, end, 'E');
if (end.size() == 0)
{
cout << -1 << endl;
exit(0);
}
cout << end[0].F << endl;
}Test details
Test 1
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 10 10 9 S293#35616 #662963731 54975451#7 5162589168 ... |
| correct output |
|---|
| 25 |
| user output |
|---|
| 25 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 0 ................................. |
| correct output |
|---|
| 301 |
| user output |
|---|
| 301 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 0 .#.........#.#..##..#............ |
| correct output |
|---|
| 253 |
| user output |
|---|
| 253 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 0 ...#......##.##.#.#..##..#..##... |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 1 0 . . . . ... |
| correct output |
|---|
| 77 |
| user output |
|---|
| 77 |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
| input |
|---|
| 1 500 0 ................................. |
| correct output |
|---|
| 166 |
| user output |
|---|
| 166 |
Test 7
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 9 ................................. |
| correct output |
|---|
| 3447 |
| user output |
|---|
| 3447 |
Test 8
Group: 2, 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500 500 9 .#........#..................#... |
| correct output |
|---|
| 4952 |
| user output |
|---|
| (empty) |
Test 9
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 9 ##.########.##########.#..#...... |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 |
Test 10
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500 500 9 623475428948841896621266296765... |
| correct output |
|---|
| 205 |
| user output |
|---|
| (empty) |
Test 11
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500 500 9 7##814125813#3463#272134469457... |
| correct output |
|---|
| 157 |
| user output |
|---|
| (empty) |
Test 12
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 9 ##67##36##5#3###67###8972#61##... |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 |
Test 13
Group: 3
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 500 500 9 ....................#...#........ |
| correct output |
|---|
| 1313 |
| user output |
|---|
| (empty) |
Test 14
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 499 499 9 S#...#...#...#...#...#...#...#... |
| correct output |
|---|
| 1124942 |
| user output |
|---|
| 1124942 |
Test 15
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 500 1 9 1 6 1 3 ... |
| correct output |
|---|
| 332 |
| user output |
|---|
| 332 |
Test 16
Group: 3
Verdict: ACCEPTED
| input |
|---|
| 1 500 9 996327784392827829434482995353... |
| correct output |
|---|
| 135 |
| user output |
|---|
| 135 |
Test 17
Group: 2, 3
Verdict: ACCEPTED
| input |
|---|
| 500 500 9 ................................. |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 |
