QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111578#6511. Balancing SequencesExplodingKonjacWA 36ms3560kbC++145.4kb2023-06-07 16:43:442023-06-07 16:43:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-07 16:43:47]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:3560kb
  • [2023-06-07 16:43:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
// #define OPENIOBUF

namespace FastIO
{

class FastIOBase
{
 protected:
#ifdef OPENIOBUF
	static const int BUFSIZE=1<<16;
	char buf[BUFSIZE+1];
	int buf_p=0;
#endif
	FILE *target;
	FastIOBase(FILE *f): target(f){}
	~FastIOBase()=default;
 public:
#ifdef OPENIOBUF
	virtual void flush()=0;
#endif
};

class FastOutput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
	{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
 private:
	inline void __putc(char x)
	{
#ifdef OPENIOBUF
		if(buf[buf_p++]=x,buf_p==BUFSIZE) flush();
#else
		putc(x,target);
#endif
	}
	template<typename T>
	inline void __write(T x)
	{
		char stk[64],*top=stk;
		if(x<0) return __putc('-'),__write(-x);
		do *(top++)=x%10,x/=10; while(x);
		for(;top!=stk;__putc(*(--top)+'0'));
	}
 public:
	FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
	~FastOutput(){ flush(); }
#endif
	inline FastOutput &operator <<(char x)
	{ return __putc(x),*this; }
	inline FastOutput &operator <<(const char *s)
	{ for(;*s;__putc(*(s++)));return *this; }
	inline FastOutput &operator <<(const string &s)
	{ return (*this)<<s.c_str(); }
	template<typename T>
	inline enable_if_t<is_integral<T>::value,FastOutput&> operator <<(const T &x)
	{ return __write(x),*this; }
	template<typename ...T>
	inline void writesp(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
	template<typename ...T>
	inline void writeln(const T &...x)
	{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
	template<typename Iter>
	inline void writesp(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<' '; }
	template<typename Iter>
	inline void writeln(Iter begin,Iter end)
	{ while(begin!=end) (*this)<<*(begin++)<<'\n'; }
}qout;

class FastInput final: public FastIOBase
{
#ifdef OPENIOBUF
 public:
	inline void flush()
	{ buf[fread(buf,1,BUFSIZE,target)]=EOF,buf_p=0; }
#endif
 private:
	bool __eof;
	inline char __getc()
	{
		if(__eof) return EOF;
#ifdef OPENIOBUF
		if(buf_p==BUFSIZE) flush();
		char ch=buf[buf_p++];
#else
		char ch=getc(target);
#endif
		return ~ch?ch:(__eof=true,EOF);
	}
	inline void __ungetc(char c)
	{
		__eof=false;
#ifdef OPENIOBUF
		buf_p--;
#else
		ungetc(c,target);
#endif
	}
 public:
	FastInput(FILE *f=stdin): FastIOBase(f),__eof(false)
#ifdef OPENIOBUF
	{ buf_p=BUFSIZE; }
	inline bool eof()const { return buf[buf_p]==EOF; }
#else
	{}
	inline bool eof()const { return feof(target); }
#endif
	inline char peek() { return __getc(); }
	explicit inline operator bool()const { return !__eof; }
	inline FastInput &operator >>(char &x)
	{ while(isspace(x=__getc()));return *this; }
	template<typename T>
	inline enable_if_t<is_integral<T>::value,FastInput&> operator >>(T &x)
	{
		char ch,sym=0;x=0;
		while(isspace(ch=__getc()));
		if(__eof) return *this;
		if(ch=='-') sym=1,ch=__getc();
		for(x=0;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
		return __ungetc(ch),sym?x=-x:x,*this;
	}
	inline FastInput &operator >>(char *s)
	{
		while(isspace(*s=__getc()));
		if(__eof) return *this;
		for(;!isspace(*s) && !__eof;*(++s)=__getc());
		return __ungetc(*s),*s='\0',*this;
	}
	inline FastInput &operator >>(string &s)
	{
		char str_buf[(1<<8)+1]={0},*p=str_buf;
		char *const buf_end=str_buf+(1<<8);
		while(isspace(*p=__getc()));
		if(__eof) return *this;
		for(s.clear(),p++;;p=str_buf)
		{
			for(;p!=buf_end && !isspace(*p=__getc()) && !__eof;p++);
			if(p!=buf_end) break;
			s.append(str_buf);
		}
		__ungetc(*p),*p='\0',s.append(str_buf);
		return *this;
	}
	template<typename ...T>
	inline void read(T &...x)
	{ initializer_list<int>{(this->operator>>(x),0)...}; }
	template<typename Iter>
	inline void read(Iter begin,Iter end)
	{ while(begin!=end) (*this)>>*(begin++); }
}qin;

} // namespace FastIO
using FastIO::qin,FastIO::qout;

using LL=long long;
using LD=long double;
using UI=unsigned int;
using ULL=unsigned long long;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

using Point=array<int,2>;
int T,n,a[2][2005],b[2][2005];
Point pa[4005],pb[4005];

#define NO_IF(cond) { if(cond) { qout<<"-1\n";goto clear_all_data; } }
vector<pair<Point,Point>> ans;
inline bool check(Point p)
{
	return a[p[0]][p[1]]>a[p[0]^1][p[1]];
}
inline bool pushAns(Point p1,Point p2)
{
	if(!check(p1) || !check(p2)) return false;
	ans.emplace_back(p1,p2);
	int &x=a[p1[0]][p1[1]],y=a[p2[0]][p2[1]];
	swap(x,y),swap(pa[x],pa[y]);
	return true;
}

int main()
{
	qin>>T;
	while(T--)
	{
		qin>>n;
		for(int k: {0,1}) qin.read(a[k]+1,a[k]+n+1);
		for(int k: {0,1}) qin.read(b[k]+1,b[k]+n+1);
		for(int k: {0,1}) for(int i=1;i<=n;i++)
		{
			pa[a[k][i]]=Point{k,i};
			pb[b[k][i]]=Point{k,i};
		}
		for(int i=1;i<=2*n;i++)
		{
			Point now=pa[i],nxt=pb[i];
			if(now==nxt || pushAns(now,nxt)) continue;
			NO_IF(!check(now));
			int mn=1e9;
			for(int j=1;j<=2*n;j++)
				if(check(pa[j])) mn=min(mn,j);
			NO_IF(mn>2*n);
			nxt[0]^=1,pushAns(nxt,pa[mn]),nxt[0]^=1;
			NO_IF(!pushAns(now,nxt));
		}
		qout<<ans.size()<<'\n';
		for(auto &[x,y]: ans)
		{
			qout<<(x[0]+1)<<' '<<x[1]<<' ';
			qout<<(y[0]+1)<<' '<<y[1]<<'\n';
		}
		clear_all_data: ans.clear();
	}
	return 0;
}
/*
2
2
1 2
3 4
4 3
2 1
3
1 2 4
3 5 6
1 2 4
5 3 6

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3560kb

input:

2
2
1 2
3 4
4 3
2 1
3
1 2 4
3 5 6
1 2 4
5 3 6

output:

-1
1
2 1 2 2

result:

ok correct plan (nYES = 1, nNO = 1) (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 3536kb

input:

100000
3
1 6 4
2 3 5
5 6 1
3 4 2
3
3 5 2
6 1 4
4 3 5
6 2 1
3
6 4 3
2 5 1
1 4 5
2 3 6
3
4 2 3
6 1 5
3 1 4
5 2 6
3
4 3 1
5 2 6
4 3 6
5 1 2
3
1 5 6
3 2 4
2 3 5
6 1 4
3
2 5 4
6 1 3
6 3 2
5 4 1
3
3 6 5
2 1 4
3 5 4
2 6 1
3
5 6 3
2 4 1
3 4 6
2 5 1
3
4 5 6
2 3 1
1 2 3
4 6 5
3
3 2 1
6 4 5
3 1 5
2 4 6
3
5 2 3...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
2
1 3 1 2
1 2 2 3
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 3 1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 2 1 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

wrong answer wrong plan (test case 50)