QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#155295 | #7119. Longest Trip | nowhk | Compile Error | / | / | C++20 | 2.6kb | 2023-09-01 15:26:56 | 2024-04-28 06:55:46 |
Judging History
你现在查看的是最新测评结果
- [2024-04-28 06:55:46]
- 管理员手动重测本题所有提交记录
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-09-01 15:26:57]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-09-01 15:26:56]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define siz(A) ((int)A.size())
//bool are_connected(std::vector<int> A, std::vector<int> B);
#include "longesttrip.h"
random_device R;
mt19937 G(R());
bool ck(int x,int y){return are_connected({x},{y});}
vector<int>get(const vector<int>&A,int l,int r)
{
vector<int>B;
for(int i=l;i<=r;i++)B.push_back(A[i]);
return B;
}
bool ck(int x,const vector<int>&B){return are_connected({x},B);}
bool ck(const vector<int>&A,const vector<int>&B){return are_connected(A,B);}
std::vector<int> longest_trip(int N, int D)
{
assert(D>=1);
vector<int>rem;
vector<int>up,dw;
for(int i=0;i<N;i++)rem.push_back(i);
shuffle(rem.begin(),rem.end());
up.push_back(rem[0]);
dw.push_back(rem[1]);
rem.erase(rem.begin());
rem.erase(rem.begin());
while(siz(rem))
{
shuffle(rem.begin(),rem.end(),G);
int A=rem[0];
rem.erase(rem.begin());
if(G()&1)
{
if(ck(up.back(),A))up.push_back(A);
else
{
if(ck(dw.back(),A))dw.push_back(A);
else
{
reverse(dw.begin(),dw.end());
up.insert(up.end(),dw.begin(),dw.end());
dw.clear();
dw.push_back(A);
}
}
}
else
{
if(ck(dw.back(),A))dw.push_back(A);
else
{
if(ck(up.back(),A))up.push_back(A);
else
{
reverse(dw.begin(),dw.end());
up.insert(up.end(),dw.begin(),dw.end());
dw.clear();
dw.push_back(A);
}
}
}
}
if(siz(dw)>siz(up))swap(up,dw);
int L=0,R=siz(dw)-1,op=0;
while(L<=R)
{
int cl=L,cr=R;
if(!ck(up.back(),get(dw,cl,cr)))
{
//两端都不行了,且两端有连边。
if(op)break;
op=1;
reverse(up.begin(),up.end());
continue;
}
while(cl<cr)
{
int mid=cl+cr>>1;
if(ck(up.back(),get(dw,cl,mid)))cr=mid;
else cl=mid+1;
}
if(cl<=(L+R>>1))
up.insert(up.end(),dw.begin()+cl,dw.begin()+R+1),R=cl-1;
else
{
for(int i=cl;i>=L;i--)up.push_back(dw[i]);
L=cl+1;
}
}
if(L<=R)
{
dw=get(dw,L,R);
if(!ck(up,dw))
{
if(siz(dw)>siz(up))swap(dw,up);
return up;
}
int l=0,r=siz(up)-1,L=0,R=siz(dw)-1;
while(l<r)
{
int mid=l+r>>1;
if(ck(get(up,l,mid),get(dw,L,R)))r=mid;
else l=mid+1;
}
while(L<R)
{
int mid=L+R>>1;
if(ck(get(up,l,r),get(dw,L,mid)))R=mid;
else L=mid+1;
}
rotate(up.begin(),up.begin()+l,up.end());
rotate(dw.begin(),dw.begin()+L,dw.end());
reverse(up.begin(),up.end());
up.insert(up.end(),dw.begin(),dw.end());
return up;
}
else return up;
return {};
}
Details
answer.code: In function ‘std::vector<int> longest_trip(int, int)’: answer.code:27:16: error: no matching function for call to ‘shuffle(std::vector<int>::iterator, std::vector<int>::iterator)’ 27 | shuffle(rem.begin(),rem.end()); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51, from answer.code:1: /usr/include/c++/13/bits/stl_algo.h:3742:5: note: candidate: ‘template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)’ 3742 | shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, | ^~~~~~~ /usr/include/c++/13/bits/stl_algo.h:3742:5: note: template argument deduction/substitution failed: answer.code:27:16: note: candidate expects 3 arguments, 2 provided 27 | shuffle(rem.begin(),rem.end()); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~