#include "parks.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int construct_roads(vector<int> x, vector<int> y) {
int n = sz(x);
vector<pair<pii,int>> p(n);
vector<int> u_ans, v_ans, a_ans, b_ans;
map<pii, int> ind;
for(int i = 0; i < n; i++)
p[i] = {{x[i], y[i]},i}, ind[{x[i], y[i]}] = i;
sort(all(p));
vector<vector<pii>> v(7);
queue<pii> inter[7];
for(int i = 0; i < n; i++)
v[p[i].fr.fr].pb({p[i].fr.sc, p[i].sc});
for(int i = 0, last = -1; i < sz(v[2]); i++) {
if(last == -1) last = v[2][i].fr;
if(i+1 == sz(v[2]) or v[2][i+1].fr - v[2][i].fr != 2) {
inter[2].push({last, v[2][i].fr});
last = -1;
continue;
}
u_ans.pb(v[2][i].sc);
v_ans.pb(v[2][i+1].sc);
a_ans.pb(1);
b_ans.pb(v[2][i].fr + 1);
}
for(int i = 0, last = -1; i < sz(v[6]); i++) {
if(i+1 == sz(v[6]) or v[6][i+1].fr - v[6][i].fr != 2) {
inter[6].push({last, v[6][i].fr});
last = -1;
continue;
}
u_ans.pb(v[6][i].sc);
v_ans.pb(v[6][i+1].sc);
a_ans.pb(7);
b_ans.pb(v[6][i].fr + 1);
}
vector<pii> to_add_1, to_add_2;
set<pii> used; // a e b
bool ok2 = 0, ok6 = 0;
for(int i = 0, last = -1; i < sz(v[4]); i++) {
int pos = v[4][i].fr;
if(last == -1) last = pos;
if(sz(inter[2]) and inter[2].front().sc < pos and ok2) inter[2].pop(), ok2 = 0;
if(sz(inter[2]) and inter[2].front().fr <= pos and pos <= inter[2].front().sc) {
if(last <= pos-2 and inter[2].front().fr <= pos-2) continue;
u_ans.pb(v[4][i].sc);
v_ans.pb(ind[{2,pos}]);
a_ans.pb({3});
b_ans.pb({pos-1});
used.insert({3, pos-1});
ok2 = 1;
}
if(sz(inter[6]) and inter[6].front().sc < pos and ok6) inter[6].pop(), ok6 = 0;
if(sz(inter[6]) and inter[6].front().fr <= pos and pos <= inter[6].front().sc) {
if(last <= pos-2 and inter[6].front().fr <= pos-2) continue;
to_add_2.pb({v[4][i].sc, ind[{6,pos}]});
ok6 = 1;
}
if(i+1 == sz(v[4]) or v[4][i+1].fr - v[4][i].fr != 2) last = -1;
else if(i+1 < sz(v[4])) to_add_1.pb({v[4][i].sc, v[4][i+1].sc});
}
if(ok2) inter[2].pop();
if(ok6) inter[6].pop();
if(sz(inter[2]) > 1) return 0;
if(sz(inter[2]) and sz(inter[6])) return 0;
if((sz(inter[2]) or sz(inter[6])) and sz(v[4])) return 0;
for(auto [A,B] : to_add_1) {
if(used.count({3,y[A]+1})) {
u_ans.pb(A);
v_ans.pb(B);
a_ans.pb(5);
b_ans.pb(y[A]+1);
used.insert({5,y[A]+1});
}
else {
u_ans.pb(A);
v_ans.pb(B);
a_ans.pb(3);
b_ans.pb(y[A]+1);
}
}
for(auto [A,B] : to_add_2) {
if(used.count({5,y[A]-1})) {
u_ans.pb(A);
v_ans.pb(B);
a_ans.pb(5);
b_ans.pb(y[A]+1);
}
else {
u_ans.pb(A);
v_ans.pb(B);
a_ans.pb(5);
b_ans.pb(y[A]-1);
}
}
build(u_ans, v_ans, a_ans, b_ans);
return 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
15916 KB |
Output is correct |
10 |
Correct |
4 ms |
2060 KB |
Output is correct |
11 |
Correct |
21 ms |
8636 KB |
Output is correct |
12 |
Correct |
6 ms |
2732 KB |
Output is correct |
13 |
Correct |
11 ms |
6444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
61 ms |
16020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
15916 KB |
Output is correct |
10 |
Correct |
4 ms |
2060 KB |
Output is correct |
11 |
Correct |
21 ms |
8636 KB |
Output is correct |
12 |
Correct |
6 ms |
2732 KB |
Output is correct |
13 |
Correct |
11 ms |
6444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
61 ms |
16020 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
15916 KB |
Output is correct |
10 |
Correct |
4 ms |
2060 KB |
Output is correct |
11 |
Correct |
21 ms |
8636 KB |
Output is correct |
12 |
Correct |
6 ms |
2732 KB |
Output is correct |
13 |
Correct |
11 ms |
6444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
61 ms |
16020 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
15916 KB |
Output is correct |
10 |
Correct |
4 ms |
2060 KB |
Output is correct |
11 |
Correct |
21 ms |
8636 KB |
Output is correct |
12 |
Correct |
6 ms |
2732 KB |
Output is correct |
13 |
Correct |
11 ms |
6444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
61 ms |
16020 KB |
Output is correct |
17 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
15916 KB |
Output is correct |
10 |
Correct |
4 ms |
2060 KB |
Output is correct |
11 |
Correct |
21 ms |
8636 KB |
Output is correct |
12 |
Correct |
6 ms |
2732 KB |
Output is correct |
13 |
Correct |
11 ms |
6444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
61 ms |
16020 KB |
Output is correct |
17 |
Runtime error |
95 ms |
40004 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
58 ms |
15916 KB |
Output is correct |
10 |
Correct |
4 ms |
2060 KB |
Output is correct |
11 |
Correct |
21 ms |
8636 KB |
Output is correct |
12 |
Correct |
6 ms |
2732 KB |
Output is correct |
13 |
Correct |
11 ms |
6444 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
61 ms |
16020 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Incorrect |
0 ms |
348 KB |
Given structure is not connected: There is no path between vertices 0 and 1 |
20 |
Halted |
0 ms |
0 KB |
- |