QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#155295#7119. Longest TripnowhkCompile Error//C++202.6kb2023-09-01 15:26:562023-09-01 15:26:57

Judging History

你现在查看的是测评时间为 2023-09-01 15:26:57 的历史记录

  • [2024-04-28 06:55:46]
  • 管理员手动重测本题所有提交记录
  • [2023-09-01 15:26:57]
  • 评测
  • [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++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/bits/stl_algo.h:3729:5: note: candidate: ‘template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)’
 3729 |     shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~~
/usr/include/c++/11/bits/stl_algo.h:3729:5: note:   template argument deduction/substitution failed:
answer.code:27:16: note:   candidate expects 3 arguments, 2 provided
   27 |         shuffle(rem.begin(),rem.end());
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~