QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281769 | #5305. Oscar is All You Need | Crying | WA | 1ms | 3616kb | C++17 | 2.1kb | 2023-12-10 18:36:19 | 2023-12-10 18:36:20 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const int MAXN = 1010;
int T,n,p[MAXN],q[MAXN],rk[MAXN];
typedef array<int,2> pr;
vector<pr>ret;
void opt(int x,int y){
assert(x>0);
assert(y>0);
assert(x+y<n);
//printf("opt (%d,%d)\n",x,y);
rep(i,1,n)q[i] = p[i];
rep(i,1,y)p[i] = q[n-y+i];
rep(i,1,n-x-y)p[y+i] = q[x+i];
rep(i,1,x)p[n-x+i] = q[i];
rep(i,1,n)rk[p[i]] = i;
ret.push_back({x,y});
//rep(i,1,n)cout<<p[i]<<" ";cout<<endl;
}
void solve(){
cin>>n;
rep(i,1,n)cin>>p[i],rk[p[i]] = i;
if(n == 3){ //corner case
if(p[1] < p[3])cout<<"0\n";
else cout<<"1\n1 1\n";
return;
}
ret.clear();
if(rk[1]>2)opt(1,n-rk[1]+1);
else if(rk[1] == 2)opt(2,1),opt(1,1);
rep(x,1,n-1){
if(rk[x+1] == x+1)continue;
//增量构造
if(rk[x+1] != x+2){ //简单情况
opt(x,n-rk[x+1]+2);
opt(1,x);
continue;
}
//printf("now %d\n",x);
int y = p[x+1],z = p[x+3];
auto F1 = [&](){
//printf("f1\n");
assert(x>1);
opt(x-1,n-rk[x+1]+1);
opt(rk[x]-1,n-rk[y]+1);
opt(1,n-rk[x]+1);
opt(1,1);
opt(1,x);
//printf("here\n");
};
auto F2 = [&](){
//printf("f2\n");
assert(x+2<n);
opt(x,n-rk[x+1]+1);
opt(1,n-rk[y]+1);
opt(1,1);
opt(1,n-rk[z]+1);
opt(rk[z],n-rk[1]+1);
};
//
if(x+2 == n)F1();
else if(x==1)F2();
else{
assert(z);
if(z != x+2)F2();
else F1();
}
/*
printf("done x = %d : \n",x);
rep(j,1,n)cout<<p[j]<<" ";cout<<endl;
exit(0);
*/
}
rep(i,1,n)assert(p[i] == i);
cout<<ret.size()<<"\n";
for(auto [x,y] : ret)cout<<x<<" "<<y<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>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: 3576kb
input:
2 3 1 3 2 5 4 1 2 3 5
output:
0 2 2 1 1 1
result:
ok OK in maximum 2 operations
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3616kb
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 0 29 1 5 1 7 1 1 2 9 1 3 1 1 1 9 1 3 3 8 1 3 4 7 1 5 1 1 1 7 1 5 5 5 1 5 6 5 1 7 1 1 1 5 1 7 7 4 1 8 1 1 1 4 1 8 8 3 1 8 68 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 17...
result:
wrong answer Integer parameter [name=operations] equals to 29, violates the range [0, 25]