QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691366#5305. Oscar is All You NeedFreeTimeLoveWA 1ms3960kbC++142.8kb2024-10-31 11:09:412024-10-31 11:09:41

Judging History

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

  • [2024-10-31 11:09:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3960kb
  • [2024-10-31 11:09:41]
  • 提交

answer

/*FreeTimeLove's code.
Love has a nasty habit of disappearing over night.*/
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=1e3+5;
inline int rd(){
	int ans=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	re f?-ans:ans;
}
int n,siz[N],S[5];
struct xxs{
	int k,s;
}a[N],b[N];
vector<pair<int,int> >Ans;

inline int gtp(int x){
	for(int i=1;i;i++)
		if(a[i].k==x)re i;
	re -1;
}
void add(int l,int r,int len){
	if(l<=0||r<=0)exit(1);
	int ls=0,rs=0;
	for(int i=1;i<=r;i++)b[i]=a[len-r+i],rs+=b[i].s;
	for(int i=1;i<=len-l-r;i++)b[i+r]=a[i+l];
	for(int i=1;i<=l;i++)b[len-l+i]=a[i],ls+=a[i].s;
	Ans.push_back(make_pair(ls,rs));
//	printf("[%d,%d]\n",ls,rs);
	memcpy(a,b,sizeof a[0]*(len+1));
	
//	putchar('{');
//	for(int i=1;i<=len;i++)printf("%d ",a[i].k);
//	putchar('}');
//	puts("");
}
void ud(int len){
	int K=-1,cnt=0;
	for(int i=1;i<len;i++)
		if(a[i].k+1==a[i+1].k){
			K=a[i].k;
			a[i].s+=a[i+1].s;
			break;
		}
	memcpy(b,a,sizeof b);
	for(int i=1;i<=len;i++)
		if(b[i].k==K+1)con;
		else a[++cnt]={b[i].k-(b[i].k>K),b[i].s};
	if(cnt!=len-1)exit(2);
	
//	putchar('{');
//	for(int i=1;i<len;i++)printf("%d ",a[i].k);
//	putchar('}');
//	puts("");
}

bool dfs(int x1,int x2,int x3,int x4,int d){
	if(x1==a[1].k&&x2==a[2].k&&x3==a[3].k&&x4==a[4].k)re 1;
	if(d>=6)re 0;
	if(dfs(x4,x2,x3,x1,d+1)){
		add(1,1,4);
		re 1;
	}
	if(dfs(x4,x3,x1,x2,d+1)){
		add(1,2,4);
		re 1;
	}
	if(dfs(x3,x4,x1,x2,d+1)){
		add(2,1,4);
		re 1; 
	}
	re 0;
}
int main(){
	int T=rd();
	while(T--){
		n=rd();
		for(int i=1;i<=n;i++)a[i]={rd(),1};
		if(n==3){
			if(a[1].k<a[3].k)puts("0");
			else puts("1\n1 1");
			con;
		}
		Ans.clear();
		int p;
		for(int i=n;i>4;i--){
			if(a[1].k>a[i].k){
				p=gtp(a[i].k+1);
				if(p>1){
					add(p-1,i-p,i);
				}
				else{//k+1...k
					add(1,1,i);
					p=a[1].k==1?gtp(a[i].k+1):gtp(a[1].k-1);
					add(p-1,i-p,i);
				}
			}
			else{
				if(a[i].k<i){//?...k(<i)
					p=gtp(a[i].k+1);
					add(p-1,i-p,i);
				}
				else{//?...i
					if(a[1].k==1){
						add(1,1,i);
						p=gtp(2);
						add(p-1,i-p,i);
					}
					else{
						p=gtp(a[1].k-1);
						add(p-1,i-p,i);
					}
				}
			}
			ud(i);
		}
		for(int i=1;i<=4;i++)S[a[i].k]=a[i].s;
		dfs(1,2,3,4,0);
		printf("%d\n",(int)Ans.size());
		for(auto x:Ans)printf("%d %d\n",x.first,x.second);
	}
	re 0;
}
/*
1
12
11 9 2 8 3 10 6 1 4 7 5 12

*/
}int main(){re FRTMLV::main();}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3960kb

input:

2
3
1 3 2
5
4 1 2 3 5

output:

0
6
3 1
1 2
1 1
1 1
1 1
1 1

result:

ok OK in maximum 6 operations

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3832kb

input:

120
3
1 3 2
3
3 2 1
3
2 3 1
5
1 2 3 4 5
12
11 9 2 8 3 10 6 1 4 7 5 12
36
24 9 7 3 31 15 13 1 4 33 11 29 16 23 2 25 35 21 32 14 6 18 17 26 28 8 27 22 20 36 10 19 34 12 30 5
4
4 2 3 1
5
3 5 2 1 4
4
1 2 4 3
10
5 7 4 9 6 8 1 3 10 2
5
3 1 5 2 4
5
3 5 1 2 4
3
3 1 2
13
3 1 2 11 12 13 8 6 5 4 10 9 7
16
12 8...

output:

0
1
1 1
1
1 1
8
1 1
1 3
2 2
1 3
1 2
1 1
1 1
1 1
13
5 6
2 9
6 5
9 1
3 8
7 4
7 4
3 7
9 1
1 9
5 1
1 5
5 1
41
20 15
21 14
12 23
8 27
33 2
1 33
10 25
13 22
24 11
22 12
21 14
20 15
20 15
28 7
5 28
19 15
3 2
5 27
9 25
31 2
6 29
7 28
18 16
18 16
12 21
3 2
23 12
15 19
30 3
27 6
20 14
4 5
5 30
26 6
10 25
10 1...

result:

wrong answer Jury have smaller lexicographical order