| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 938938 | AdamGS | 가장 긴 여행 (IOI23_longesttrip) | C++17 | 12 ms | 952 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 "longesttrip.h"
#include<bits/stdc++.h>
using namespace std;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
vector<int>longest_trip(int n, int d) {
vector<pair<int,int>>X, Y;
vector<int>A, B;
rep(i, n/2) if(are_connected({2*i}, {2*i+1})) X.pb({2*i, 2*i+1}); else Y.pb({2*i, 2*i+1});
if(n%2==1) A.pb(n-1);
for(auto i : X) {
if(A.size()==0) {
A.pb(i.st);
A.pb(i.nd);
continue;
}
if(B.size()==0) {
B.pb(i.st);
B.pb(i.nd);
continue;
}
if(are_connected({A.back()}, {i.st})) {
A.pb(i.st);
A.pb(i.nd);
continue;
}
if(are_connected({B.back()}, {i.st})) {
B.pb(i.st);
B.pb(i.nd);
continue;
}
reverse(all(B));
for(auto j : B) A.pb(j);
B.clear();
B.pb(i.st);
B.pb(i.nd);
}
for(auto i : Y) {
if(A.size()==0) {
A.pb(i.st);
B.pb(i.nd);
continue;
}
if(!are_connected({A.back()}, {i.st})) swap(i.st, i.nd);
A.pb(i.st);
if(B.size()==0 || are_connected({B.back()}, {i.nd})) {
B.pb(i.nd);
continue;
}
reverse(all(B));
for(auto j : B) A.pb(j);
B.clear();
B.pb(i.nd);
}
if(A.size()==n) return A;
if(!are_connected(A, B)) {
if(A.size()<B.size()) return B;
return A;
}
if(are_connected({A.back()}, {B.back()})) {
reverse(all(B));
for(auto i : B) A.pb(i);
return A;
}
if(are_connected({A.back()}, {B[0]})) {
for(auto i : B) A.pb(i);
return A;
}
if(are_connected({A[0]}, {B.back()})) {
for(auto i : A) B.pb(i);
return B;
}
if(are_connected({A[0]}, {B[0]})) {
reverse(all(A));
for(auto i : B) A.pb(i);
return A;
}
int po=0, ko=A.size()-1;
while(po<ko) {
int sr=(po+ko)/2;
vector<int>C;
rep(i, sr+1) C.pb(A[i]);
if(are_connected(C, B)) ko=sr; else po=sr+1;
}
int x=po;
po=0; ko=B.size()-1;
while(po<ko) {
int sr=(po+ko)/2;
vector<int>C, D;
rep(i, x+1) C.pb(A[i]);
rep(i, sr+1) D.pb(B[i]);
if(are_connected(C, D)) ko=sr; else po=sr+1;
}
int y=po;
vector<int>ans;
rep(i, A.size()) ans.pb(A[(x+i+1)%A.size()]);
rep(i, B.size()) ans.pb(B[(y+i)%B.size()]);
return ans;
}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... | ||||
