QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#306479#5305. Oscar is All You NeedlnyxWA 0ms3664kbC++142.3kb2024-01-16 19:57:222024-01-16 19:57:22

Judging History

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

  • [2024-01-16 19:57:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3664kb
  • [2024-01-16 19:57:22]
  • 提交

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 void solve(){
	ans.clear();
	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 val=2;val<=n-2;val++){
		int pos=0;
		for(int i=1;i<=n;i++){
			if(p[i]==val) pos=i;
		}
		if(pos==val) continue;
		if(pos>val+1) change(val-1,n-pos+2),change(1,val-1);
		else change(val-1,1),change(pos-1-(val-1)+1,val-1);
		// for(int i=1;i<=n;i++) cerr<<p[i]<<" \n"[i==n];
	}
	if(p[n-1]>p[n]) change(1,1),change(1,2),change(1,1),change(2,1),change(1,1);
	// for(int i=1;i<=n;i++) cerr<<p[i]<<" \n"[i==n];
	assert((int)ans.size()<=n*2+1);
	for(int i=1;i<=n;i++) assert(p[i]==i);
	wt('\n',(int)ans.size());
	for(PII A:ans) assert(A.first&&A.second),wt('\n',' ',A.first,A.second);
}
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: 0ms
memory: 3664kb

input:

2
3
1 3 2
5
4 1 2 3 5

output:

0
4
1 2 
1 3 
2 2 
1 2 

result:

ok OK in maximum 4 operations

Test #2:

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

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
0
17
1 5 
1 7 
1 1 
2 1 
2 2 
3 7 
1 3 
4 1 
2 4 
5 4 
1 5 
6 1 
2 6 
7 4 
1 7 
8 2 
1 8 
65
1 29 
1 30 
1 1 
2 12 
1 2 
3 30 
1 3 
4 8 
1 4 
5 16 
1 5 
6 16 
1 6 
7 12 
1 7 
8 20 
1 8 
9 6 
1 9 
10 18 
1 10 
11 8 
1 11 
12 22 
1 12 
13 15 
1 13 
14 11 
1 14 
15 19 
1 15 
16 15 
1 16 
...

result:

wrong answer x+y is greater than n