QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#306209#5305. Oscar is All You NeedlnyxWA 2ms3664kbC++142.2kb2024-01-16 15:20:182024-01-16 15:20:19

Judging History

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

  • [2024-01-16 15:20:19]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3664kb
  • [2024-01-16 15:20:18]
  • 提交

answer

// 距离退役还有 47 天
#include<cstdio>
#include<iostream>
#include<vector>
#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(){
	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(len==n-1&&p[n]==n) break;
		if(len==n-1&&p[n]==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);
		// 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);
}
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;
}

详细

Test #1:

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

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: 2ms
memory: 3660kb

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 
31
1 2 
1 1 
1 2 
1 1 
1 2 
1 1 
1 2 
1 1 
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 
102
1 2 
1 1 
1 2 
1 1 
1 2 
1 1 
1 2 
1 1 
1 5 
1 2 
1 1 
1 2 
1 1 
2 2 
1 2 
1 2 
1 ...

result:

wrong answer x+y is greater than n