This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include "longesttrip.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
#define N 256
int nxt[N];
vector<int> solve1(int n){
int a,b,p,q,x,y,z;
a=b=0;p=q=1;
x=y=1;
for(int i=2;i<n;i++){
if(are_connected({b},{i})){
nxt[b]=i;
x++;
b=i;
}
else if(are_connected({i},{p})){
nxt[i]=p;
y++;
p=i;
}
else{
nxt[b]=p;
x+=y;
b=q;
y=1;
p=q=i;
}
}
if(x>y) z=a;
else z=p;
vector<int> v;
for(int i=0;i<max(x,y);i++){
v.append(z);
z=nxt[z];
}
return v;
}
vector<int> solve2(int n){
int p,q,r;
p=0;
q=1;
r=are_connected({0},{1});
if(r) nxt[0]=1;
else{
nxt[0]=2;
nxt[2]=1;
}
for(int i=3-r;i<n;i++){
if(are_connected({q},{i})){
nxt[q]=i;
q=i;
}
else{
nxt[i]=p;
p=i;
}
}
vector<int> v;
for(int i=0;i<n;i++){
v.append(p);
p=nxt[p];
}
return v;
}
vector<int> solve3(int n){
vector<int> v;
for(int i=0;i<n;i++)
v.append(i);
return v;
}
vector<int> longest_trip(int n,int d){
if(d==3) return solve3(n);
if(d==2) return solve2(n);
return solve1(n);
}
# | 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... |