# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
435576 |
2021-06-23T12:45:10 Z |
grt |
Fountain Parks (IOI21_parks) |
C++17 |
|
823 ms |
155920 KB |
#include <bits/stdc++.h>
#include "parks.h"
#define ST first
#define ND second
#define PB push_back
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 400 * 1000 + 10;
map<pi, int>fontain;
pi road[nax];
int n;
vi V[nax], V2[nax];
map<pi, int>pts;
pi inv[nax];
bool vis[nax];
int match[nax];
bool augument(int u) {
vis[u] = true;
for(int v : V[u]) {
if(match[v] == -1) {
match[u] = v;
match[v] = u;
return true;
}
}
for(int v : V[u]) {
if(!vis[match[v]] && augument(match[v])) {
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
void dfs(int x) {
vis[x] = true;
for(int nbh : V2[x]) if(!vis[nbh]) {
dfs(nbh);
}
}
int construct_roads(vi xx, vi yx) {
for(int i = 0; i < (int)xx.size(); ++i) {
fontain[{xx[i], yx[i]}] = i;
}
for(auto it : fontain) {
auto [x, y] = it.ST;
if(fontain.count({x + 2, y})) {
road[n] = {it.ND, fontain[{x + 2, y}]};
pts[{x + 1, y - 1}];
pts[{x + 1, y + 1}];
n++;
}
if(fontain.count({x, y + 2})) {
road[n] = {it.ND, fontain[{x, y + 2}]};
pts[{x - 1, y + 1}];
pts[{x + 1, y + 1}];
n++;
}
}
int id = 0;
for(auto &it : pts) {
inv[id] = it.ST;
it.ND = id++;
}
for(int i = 0; i < n; ++i) {
V2[road[i].ST].PB(road[i].ND);
V2[road[i].ND].PB(road[i].ST);
int x1 = xx[road[i].ST], y1 = yx[road[i].ST];
int x2 = xx[road[i].ND], y2 = yx[road[i].ND];
if(x1 == x2) {
int y = (y1 + y2) / 2;
for(int x : {x1 - 1, x1 + 1}) {
int nr = pts[{x, y}];
V[i].emplace_back(n + nr);
V[n + nr].emplace_back(i);
}
} else if(y1 == y2) {
int x = (x1 + x2) / 2;
for(int y : {y1 - 1, y1 + 1}) {
int nr = pts[{x, y}];
V[i].emplace_back(n + nr);
V[n + nr].emplace_back(i);
}
}
}
dfs(0);
for(int i = 0; i < (int)xx.size(); ++i) {
if(!vis[i]) {
return 0;
}
}
for(int i = 0; i < n + id; ++i) {
match[i] = -1;
}
while(true) {
bool any = false;
for(int i = 0; i < n + id; ++i) {
vis[i] = false;
}
for(int i = 0; i < n + id; ++i) {
if(match[i] == -1 && augument(i)) {
any = true;
}
}
if(!any) break;
}
for(int i = 0; i < n; ++i) {
if(match[i] == -1) {
return 0;
}
}
vi u(n), v(n), a(n), b(n);
for(int i = 0; i < n; ++i) {
u[i] = road[i].ST;
v[i] = road[i].ND;
a[i] = inv[match[i] - n].ST;
b[i] = inv[match[i] - n].ND;
}
build(u,v,a,b);
return 1;
}
//int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19020 KB |
Output is correct |
2 |
Correct |
13 ms |
19032 KB |
Output is correct |
3 |
Correct |
12 ms |
19008 KB |
Output is correct |
4 |
Correct |
12 ms |
19108 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
13 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19040 KB |
Output is correct |
8 |
Correct |
12 ms |
19104 KB |
Output is correct |
9 |
Correct |
333 ms |
62052 KB |
Output is correct |
10 |
Correct |
35 ms |
23496 KB |
Output is correct |
11 |
Correct |
157 ms |
42440 KB |
Output is correct |
12 |
Correct |
49 ms |
25724 KB |
Output is correct |
13 |
Correct |
140 ms |
35156 KB |
Output is correct |
14 |
Correct |
15 ms |
19404 KB |
Output is correct |
15 |
Correct |
16 ms |
19716 KB |
Output is correct |
16 |
Correct |
348 ms |
61348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19020 KB |
Output is correct |
2 |
Correct |
13 ms |
19032 KB |
Output is correct |
3 |
Correct |
12 ms |
19008 KB |
Output is correct |
4 |
Correct |
12 ms |
19108 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
13 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19040 KB |
Output is correct |
8 |
Correct |
12 ms |
19104 KB |
Output is correct |
9 |
Correct |
333 ms |
62052 KB |
Output is correct |
10 |
Correct |
35 ms |
23496 KB |
Output is correct |
11 |
Correct |
157 ms |
42440 KB |
Output is correct |
12 |
Correct |
49 ms |
25724 KB |
Output is correct |
13 |
Correct |
140 ms |
35156 KB |
Output is correct |
14 |
Correct |
15 ms |
19404 KB |
Output is correct |
15 |
Correct |
16 ms |
19716 KB |
Output is correct |
16 |
Correct |
348 ms |
61348 KB |
Output is correct |
17 |
Correct |
12 ms |
19068 KB |
Output is correct |
18 |
Correct |
11 ms |
19020 KB |
Output is correct |
19 |
Correct |
13 ms |
19096 KB |
Output is correct |
20 |
Correct |
12 ms |
19072 KB |
Output is correct |
21 |
Correct |
12 ms |
19020 KB |
Output is correct |
22 |
Correct |
14 ms |
19020 KB |
Output is correct |
23 |
Runtime error |
491 ms |
117820 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19020 KB |
Output is correct |
2 |
Correct |
13 ms |
19032 KB |
Output is correct |
3 |
Correct |
12 ms |
19008 KB |
Output is correct |
4 |
Correct |
12 ms |
19108 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
13 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19040 KB |
Output is correct |
8 |
Correct |
12 ms |
19104 KB |
Output is correct |
9 |
Correct |
333 ms |
62052 KB |
Output is correct |
10 |
Correct |
35 ms |
23496 KB |
Output is correct |
11 |
Correct |
157 ms |
42440 KB |
Output is correct |
12 |
Correct |
49 ms |
25724 KB |
Output is correct |
13 |
Correct |
140 ms |
35156 KB |
Output is correct |
14 |
Correct |
15 ms |
19404 KB |
Output is correct |
15 |
Correct |
16 ms |
19716 KB |
Output is correct |
16 |
Correct |
348 ms |
61348 KB |
Output is correct |
17 |
Correct |
12 ms |
19068 KB |
Output is correct |
18 |
Correct |
11 ms |
19020 KB |
Output is correct |
19 |
Correct |
13 ms |
19096 KB |
Output is correct |
20 |
Correct |
12 ms |
19072 KB |
Output is correct |
21 |
Correct |
12 ms |
19020 KB |
Output is correct |
22 |
Correct |
14 ms |
19020 KB |
Output is correct |
23 |
Runtime error |
491 ms |
117820 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19020 KB |
Output is correct |
2 |
Correct |
13 ms |
19032 KB |
Output is correct |
3 |
Correct |
12 ms |
19008 KB |
Output is correct |
4 |
Correct |
12 ms |
19108 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
13 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19040 KB |
Output is correct |
8 |
Correct |
12 ms |
19104 KB |
Output is correct |
9 |
Correct |
333 ms |
62052 KB |
Output is correct |
10 |
Correct |
35 ms |
23496 KB |
Output is correct |
11 |
Correct |
157 ms |
42440 KB |
Output is correct |
12 |
Correct |
49 ms |
25724 KB |
Output is correct |
13 |
Correct |
140 ms |
35156 KB |
Output is correct |
14 |
Correct |
15 ms |
19404 KB |
Output is correct |
15 |
Correct |
16 ms |
19716 KB |
Output is correct |
16 |
Correct |
348 ms |
61348 KB |
Output is correct |
17 |
Correct |
12 ms |
19084 KB |
Output is correct |
18 |
Correct |
12 ms |
19020 KB |
Output is correct |
19 |
Correct |
13 ms |
19120 KB |
Output is correct |
20 |
Correct |
823 ms |
96188 KB |
Output is correct |
21 |
Correct |
742 ms |
88360 KB |
Output is correct |
22 |
Correct |
718 ms |
88388 KB |
Output is correct |
23 |
Runtime error |
548 ms |
146064 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19020 KB |
Output is correct |
2 |
Correct |
13 ms |
19032 KB |
Output is correct |
3 |
Correct |
12 ms |
19008 KB |
Output is correct |
4 |
Correct |
12 ms |
19108 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
13 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19040 KB |
Output is correct |
8 |
Correct |
12 ms |
19104 KB |
Output is correct |
9 |
Correct |
333 ms |
62052 KB |
Output is correct |
10 |
Correct |
35 ms |
23496 KB |
Output is correct |
11 |
Correct |
157 ms |
42440 KB |
Output is correct |
12 |
Correct |
49 ms |
25724 KB |
Output is correct |
13 |
Correct |
140 ms |
35156 KB |
Output is correct |
14 |
Correct |
15 ms |
19404 KB |
Output is correct |
15 |
Correct |
16 ms |
19716 KB |
Output is correct |
16 |
Correct |
348 ms |
61348 KB |
Output is correct |
17 |
Runtime error |
525 ms |
155920 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
19020 KB |
Output is correct |
2 |
Correct |
13 ms |
19032 KB |
Output is correct |
3 |
Correct |
12 ms |
19008 KB |
Output is correct |
4 |
Correct |
12 ms |
19108 KB |
Output is correct |
5 |
Correct |
12 ms |
19020 KB |
Output is correct |
6 |
Correct |
13 ms |
19020 KB |
Output is correct |
7 |
Correct |
12 ms |
19040 KB |
Output is correct |
8 |
Correct |
12 ms |
19104 KB |
Output is correct |
9 |
Correct |
333 ms |
62052 KB |
Output is correct |
10 |
Correct |
35 ms |
23496 KB |
Output is correct |
11 |
Correct |
157 ms |
42440 KB |
Output is correct |
12 |
Correct |
49 ms |
25724 KB |
Output is correct |
13 |
Correct |
140 ms |
35156 KB |
Output is correct |
14 |
Correct |
15 ms |
19404 KB |
Output is correct |
15 |
Correct |
16 ms |
19716 KB |
Output is correct |
16 |
Correct |
348 ms |
61348 KB |
Output is correct |
17 |
Correct |
12 ms |
19068 KB |
Output is correct |
18 |
Correct |
11 ms |
19020 KB |
Output is correct |
19 |
Correct |
13 ms |
19096 KB |
Output is correct |
20 |
Correct |
12 ms |
19072 KB |
Output is correct |
21 |
Correct |
12 ms |
19020 KB |
Output is correct |
22 |
Correct |
14 ms |
19020 KB |
Output is correct |
23 |
Runtime error |
491 ms |
117820 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |