# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
172009 | kostia244 | Highway design (CEOI12_highway) | C++17 | 9 ms | 5604 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"office.h"
#include<bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
#define iol isOnLine
int n;
vpi bad;
void check(vpi a) {
// cout << "++\n";
if(bad.empty()) {
if(a[0].second<2||a[1].second<2||a[2].second<2) {
for(auto i : a) bad.pb(i);
return;
}
for(int i = 1; i < 3; i++) {
if(iol(a[0].first, a[0].first+1, a[i].first)) {
Answer(a[0].first, a[0].first+1,a[3^i].first, a[3^i].first+1);
exit(0);
}
}
Answer(a[1].first, a[1].first+1,a[2].first, a[2].first+1);
exit(0);
}
for(int i = 0; i < 3; i++) {
for(int j = i+1; j < 3; j++) {
vpi z[2];
for(int k = 0; k <3; k++)
z[iol(a[i].first, a[j].first, bad[k].first)].pb(bad[k]);
if(z[0].size()&&z[1].size()) {
Answer(a[i].first, a[j].first, a[3^i^j].first, z[0][0].first);
exit(0);
}
}
}
}
void solve(vpi a) {
// cout << a.size() << "\n";
if(a.size()==2) {
Answer(a[0].first, a[0].first+1,a[1].first, a[1].first+1);
exit(0);
}
if(a.size()==1) {
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if(i==j) continue;
if(iol(bad[i].first, bad[j].first, a[0].first)) {
Answer(bad[i].first, bad[j].first, bad[3^i^j].first, bad[3^i^j].first+1);
}
}
}
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if(bad[i].second<2||i==j) continue;
if(iol(bad[i].first, bad[i].first+1, bad[j].first)) {
Answer(bad[i].first, bad[j].first, bad[3^i^j].first, a[0].first);
}
}
}
}
vpi t;
int x = 0;
while(x+2 < a.size()) {
if(iol(a[x].first, a[x+1].first, a[x+2].first)) {
t.pb({a[x].first, a[x].second+a[x+1].second+a[x+2].second});
} else {
check({a[x], a[x+1], a[x+2]});
}
x+=3;
}
while(x < a.size()) t.pb(a[x++]);
solve(t);
}
int main() {
n = GetN();
vpi a;
for(int i = 1; i <= n; i++) a.pb({i, 1});
solve(a);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |