# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
831544 | andrey27_sm | Fountain Parks (IOI21_parks) | C++17 | 123 ms | 23208 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> cons[200001];
int mask_l[200001];
vector<int> u;
vector<int> v;
vector<int> a;
vector<int> b;
int construct_roads(vector<int> x, vector<int> y) {
int n = x.size();
int l = 1e9;
int r = 0;
for (int i = 0; i < n; ++i)
{
cons[y[i]/2].push_back({x[i],i});
mask_l[y[i]/2]|=(1<<(x[i]/2-1));
}
for (int i = 0; i <= 100000; ++i)
{
if(mask_l[i]){
l = min(l,i);
r = max(r,i);
sort(cons[i].begin(), cons[i].end());
}
}
for (int i = l; i <= r; ++i)
{
if(i != l and (mask_l[i]&mask_l[i-1]) == 0) return 0;
}
int p = l+1;
bool con = 1;
if(mask_l[l] != 5)
{
for(int i = 0;i+1 < cons[l].size();i++){
u.push_back(cons[l][i].second);
v.push_back(cons[l][i+1].second);
a.push_back(cons[l][i].first+1);
b.push_back(2*l-1);
}
}
else{
con = 0;
}
while(p <= r){
if(mask_l[p] == 5 and (mask_l[p-1]&mask_l[p]) != 5) con = 0;
if(con == 0){
if(mask_l[p] == 5){
for(auto e:cons[p-1]){
if(e.first == 2){
u.push_back(e.second);
v.push_back(cons[p][0].second);
a.push_back(e.first-1);
b.push_back(2*p-1);
}
if(e.first == 6){
u.push_back(e.second);
v.push_back(cons[p][1].second);
a.push_back(e.first+1);
b.push_back(2*p-1);
}
}
}
else if(mask_l[p] == 7){
for(auto e:cons[p-1]){
if(e.first == 2){
u.push_back(e.second);
v.push_back(cons[p][0].second);
a.push_back(e.first-1);
b.push_back(2*p-1);
}
if(e.first == 6){
u.push_back(e.second);
v.push_back(cons[p][1].second);
a.push_back(e.first+1);
b.push_back(2*p-1);
}
}
u.push_back(cons[p][0].second);
v.push_back(cons[p][1].second);
a.push_back(cons[p][1].first-1);
b.push_back(2*p-1);
u.push_back(cons[p][1].second);
v.push_back(cons[p][2].second);
a.push_back(cons[p][2].first-1);
b.push_back(2*p-1);
con = 1;
}
else return 0;
}
else if(mask_l[p] == 7 and mask_l[p-1] == 2){
u.push_back(cons[p][0].second);
v.push_back(cons[p][1].second);
a.push_back(cons[p][1].first-1);
b.push_back(2*p-1);
u.push_back(cons[p][1].second);
v.push_back(cons[p][2].second);
a.push_back(cons[p][2].first-1);
b.push_back(2*p+1);
u.push_back(cons[p-1][0].second);
v.push_back(cons[p][1].second);
a.push_back(cons[p][1].first+1);
b.push_back(2*p-1);
}
else if(mask_l[p-1] == 7){
for(auto e:cons[p]){
if(e.first == 2 or e.first == 4){
u.push_back(e.second);
v.push_back(cons[p-1][e.first/2-1].second);
a.push_back(e.first-1);
b.push_back(2*p-1);
}
else{
u.push_back(e.second);
v.push_back(cons[p-1][e.first/2-1].second);
a.push_back(e.first+1);
b.push_back(2*p-1);
}
}
}
else{
int mask_blocked = 0;
if((mask_l[p]&3) == 3 and (mask_l[p-1]&3) != 3){
u.push_back(cons[p][0].second);
v.push_back(cons[p][1].second);
a.push_back(cons[p][1].first-1);
b.push_back(2*p-1);
mask_blocked|=1;
}
if(((mask_l[p]>>1)&3) == 3 and ((mask_l[p-1]>>1)&3) != 3){
u.push_back(cons[p][0+(mask_l[p]&1)].second);
v.push_back(cons[p][1+(mask_l[p]&1)].second);
a.push_back(cons[p][1+(mask_l[p]&1)].first-1);
b.push_back(2*p-1);
mask_blocked|=2;
}
for(auto e:cons[p]){
for(auto E:cons[p-1]){
if(e.first != E.first) continue;
//cout << e.second << " " << E.second << "--\n";
u.push_back(e.second);
v.push_back(E.second);
b.push_back(2*p-1);
if(e.first == 2) a.push_back(1);
else if(e.first == 6) a.push_back(7);
else if(mask_blocked&1){
a.push_back(5);
}
else{
a.push_back(3);
}
}
}
}
p++;
}
if(con == 0) return 0;
build(u,v,a,b);
return 1;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |