QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#281814 | #5305. Oscar is All You Need | Crying | RE | 0ms | 3680kb | C++17 | 1.6kb | 2023-12-10 20:58:32 | 2023-12-10 20:58:34 |
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);
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});
}
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){
int y = p[x+1];
auto F = [&](){
x--; y = p[x+1];
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);
};
int j = x;
while(p[j] > p[x+1])j--;
if(j == x) continue;
if(j == n-2){
F();break;
}else{
opt(j,2);
opt(1,j);
}
}
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;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
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
Runtime Error
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...