QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#306273#5305. Oscar is All You NeedlnyxWA 1ms3624kbC++142.3kb2024-01-16 16:44:542024-01-16 16:44:55

Judging History

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

  • [2024-01-16 16:44:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-01-16 16:44:54]
  • 提交

answer

// 距离退役还有 47 天
#include<cstdio>
#include<iostream>
#include<vector>
#include<cassert>
#define eb emplace_back
using namespace std;
namespace IO{
	template<typename T> inline void rd(T &x){
		x=0; bool f=0; char c=getchar();
		while(c<'0'||c>'9') f|=c=='-',c=getchar();
		while('0'<=c&&c<='9') x=((x<<3)+(x<<1))+(c^48),c=getchar();
		x=f?-x:x;
	}
	template<typename T,typename ...Args> inline void rd(T &x,Args &...args){ rd(x),rd(args...); }
	template<typename T> inline void wt(char c,T x){
		static int stk[114]; int top=0;
		if(x<0) x=-x,putchar('-');
		do stk[++top]=x%10,x/=10; while(x);
		while(top) putchar(stk[top--]+'0');
		putchar(c);
	}
	template<typename T,typename ...Args> inline void wt(char c,T x,Args ...args){ wt(c,x),wt(c,args...); }
	template<typename T,typename ...Args> inline void wt(char c1,char c2,T x,Args ...args){ wt(c2,x),wt(c2,args...),putchar(c1); }
}
using IO::rd;
using IO::wt;
typedef pair<int,int> PII;
const int N=1007;
int n;
int p[N],tmp[N];
vector<PII>ans;
inline void change(int x,int y){
	ans.eb(x,y);
	int cnt=0;
	for(int i=n-y+1;i<=n;i++) tmp[++cnt]=p[i];
	for(int i=x+1;i<n-y+1;i++) tmp[++cnt]=p[i];
	for(int i=1;i<=x;i++) tmp[++cnt]=p[i];
	for(int i=1;i<=n;i++) p[i]=tmp[i];
}
inline int chk(){
	for(int i=1;i<=n;i++){
		if(p[i]!=i) return 0;
	}
	return 1;
}
inline void solve(){
	rd(n);
	for(int i=1;i<=n;i++) rd(p[i]);
	if(n==3){
		if(p[3]<p[1]) puts("1\n1 3");
		else puts("0");
		return ;
	}
	if(p[1]!=1){
		if(p[2]==1) change(1,2);
		int pos=0;
		for(int i=1;i<=n;i++){
			if(p[i]==1){ pos=i; break; }
		}
		change(1,n-pos+1);
	}
	// for(int i=1;i<=n;i++) cerr<<p[i]<<" \n"[i==n];
	for(int len=1;len<=n;len++){
		int pos=0;
		for(int i=1;i<=len;i++){
			if(p[i]<p[n]) pos=i;
		}
		if(pos+2>=n){
			continue;
			if(pos!=n-1) change(n-2,1),change(1,1),change(1,n-2),change(1,n-2),change(1,1);
		}
		else change(pos,2),change(1,pos);
		if(chk()) break;
		// for(int i=1;i<=n;i++) cerr<<p[i]<<" \n"[i==n];
	}
	/*
	1 2 4 3
	3 4 1 2
	2 4 1 3
	1 3 4 2
	4 2 3 1
	1 2 3 4
	*/
	wt('\n',(int)ans.size());
	for(PII A:ans) wt('\n',' ',A.first,A.second);
	ans.clear();
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int T; rd(T);
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3596kb

input:

2
3
1 3 2
5
4 1 2 3 5

output:

0
10
1 2 
1 3 
1 2 
1 1 
2 2 
1 2 
2 2 
1 2 
1 2 
1 1 

result:

ok OK in maximum 10 operations

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3624kb

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 3
1
1 3
8
1 2 
1 1 
1 2 
1 1 
1 2 
1 1 
1 2 
1 1 
23
1 5 
1 2 
1 1 
1 2 
1 1 
2 2 
1 2 
1 2 
1 1 
3 2 
1 3 
1 2 
1 1 
5 2 
1 5 
8 2 
1 8 
3 2 
1 3 
5 2 
1 5 
3 2 
1 3 
71
1 29 
1 2 
1 1 
1 2 
1 1 
2 2 
1 2 
4 2 
1 4 
1 2 
1 1 
2 2 
1 2 
3 2 
1 3 
2 2 
1 2 
8 2 
1 8 
5 2 
1 5 
11 2 
1 11 
8 2 
...

result:

wrong answer x+y is greater than n