QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#163835 | #7119. Longest Trip | Crysfly | 0 | 0ms | 0kb | C++17 | 2.5kb | 2023-09-04 15:40:54 | 2024-04-28 08:15:35 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include"longesttrip.h"
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n;
int mp[260][260];
int Q(int i,int j){
if(mp[i][j]!=-1)return mp[i][j];
return mp[i][j]=mp[j][i]=are_connected({i},{j});
}
int Q(vi a,vi b){
if(a.size()==1 && b.size()==1) return Q(a[0],b[0]);
return are_connected(a,b);
}
void operator +=(vi&a,vi&b){
for(int x:b) a.pb(x);
}
mt19937_64 rnd(64);
vi longest_trip(int N,int D)
{
n=N;
For(i,0,n-1)For(j,0,n-1)mp[i][j]=(i==j?0:-1);
vi per(n);
iota(per.begin(),per.end(),0);
shuffle(per.begin(),per.end(),rnd);
vi a,b;
for(auto i:per){
if(!a.size()){
a.pb(i);
continue;
}
if(rnd()&1) swap(a,b);
if(rnd()&1) reverse(a.begin(),a.end());
if(rnd()&1) reverse(b.begin(),b.end());
if(Q(i,a.back())) a.pb(i);
else if(b.size() && Q(i,b.back())) b.pb(i);
else reverse(b.begin(),b.end()),a+=b,b.clear(),b.pb(i);
}
if(!b.size())return a;
if(!Q(a,b))return a.size()>b.size()?a:b;
if(Q(a[0],b[0])) return reverse(a.begin(),a.end()),a+=b,a;
if(Q(a.back(),b[0])) return a+=b,a;
if(Q(a[0],b.back())) return b+=a,b;
if(Q(a.back(),b.back())) return reverse(a.begin(),a.end()),b+=a,b;
vi aa=a,bb=b;
while(a.size()>1){
int mid=a.size()>>1; vi al,ar;
For(i,0,mid-1) al.pb(a[i]);
For(i,mid,a.size()-1) ar.pb(a[i]);
if(Q(al,b)) a=al;
else a=ar;
}
while(b.size()>1){
int mid=b.size()>>1; vi bl,br;
For(i,0,mid-1) bl.pb(b[i]);
For(i,mid,b.size()-1) br.pb(b[i]);
if(Q(bl,a)) b=bl;
else b=br;
}
int u=a[0],v=b[0];
a=aa,b=bb;
For(i,0,(int)a.size()-1) if(a[i]==u)
For(j,0,(int)b.size()-1) if(b[j]==v) {
vi res;
For(p,i+1,(int)a.size()-1) res.pb(a[p]);
For(p,0,i) res.pb(a[p]);
For(p,j,(int)b.size()-1) res.pb(b[p]);
For(p,0,j-1) res.pb(b[p]);
return res;
}
assert(0);
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
341 3 3 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 0 1
result:
Subtask #2:
score: 0
Runtime Error
Test #6:
score: 0
Runtime Error
input:
341 3 2 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 0 1
result:
Subtask #3:
score: 0
Runtime Error
Test #19:
score: 0
Runtime Error
input:
341 3 1 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 0 1
result:
Subtask #4:
score: 0
Runtime Error
Test #83:
score: 0
Runtime Error
input:
341 3 1 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 0 1