QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691284 | #5305. Oscar is All You Need | FreeTimeLove | RE | 1ms | 3840kb | C++14 | 2.6kb | 2024-10-31 10:44:02 | 2024-10-31 10:44:03 |
Judging History
answer
/*FreeTimeLove's code.
Love has a nasty habit of disappearing over night.*/
#include<bits/stdc++.h>
namespace FRTMLV{
#define ll long long
#define LD long double
#define i7 __int128
#define re return
#define con continue
using namespace std;
template<class T>inline bool ckmin(T &a,T b){re b<a?a=b,1:0;}
template<class T>inline bool ckmax(T &a,T b){re a<b?a=b,1:0;}
const int N=1e3+5;
inline int rd(){
int ans=0,f=0;
char ch=getchar();
while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9')ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
re f?-ans:ans;
}
int n,siz[N],S[5];
struct xxs{
int k,s;
}a[N],b[N];
vector<pair<int,int> >Ans;
inline int gtp(int x){
for(int i=1;i;i++)
if(a[i].k==x)re i;
re -1;
}
void add(int l,int r,int len){
if(l<=0||r<=0)exit(1);
int ls=0,rs=0;
for(int i=1;i<=r;i++)b[i]=a[len-r+i],rs+=b[i].s;
for(int i=1;i<=len-l-r;i++)b[i+r]=a[i+l];
for(int i=1;i<=l;i++)b[len-l+i]=a[i],ls+=a[i].s;
Ans.push_back(make_pair(ls,rs));
// printf("[%d,%d]\n",ls,rs);
memcpy(a,b,sizeof a[0]*(len+1));
}
void ud(int len){
int K=-1,cnt=0;
for(int i=1;i<len;i++)
if(a[i].k+1==a[i+1].k){
K=a[i].k;
a[i].s+=a[i+1].s;
break;
}
memcpy(b,a,sizeof b);
for(int i=1;i<=len;i++)
if(b[i].k==K+1)con;
else a[++cnt]={b[i].k-(b[i].k>K),b[i].s};
if(cnt!=len-1)exit(2);
}
bool dfs(int x1,int x2,int x3,int x4,int d){
if(x1==a[1].k&&x2==a[2].k&&x3==a[3].k&&x4==a[4].k)re 1;
if(d>=6)re 0;
if(dfs(x4,x2,x3,x1,d+1)){
add(1,1,4);
re 1;
}
if(dfs(x4,x3,x1,x2,d+1)){
add(1,2,4);
re 1;
}
if(dfs(x3,x4,x1,x2,d+1)){
add(2,1,4);
re 1;
}
re 0;
}
int main(){
int T=rd();
while(T--){
n=rd();
for(int i=1;i<=n;i++)a[i]={rd(),1};
if(n==3){
if(a[1].k<a[3].k)puts("0");
else puts("1\n1 1");
con;
}
Ans.clear();
int p;
for(int i=n;i>4;i--){
if(a[1].k>a[i].k){
p=gtp(a[i].k+1);
if(p>1){
add(p-1,n-p,i);
}
else{//k+1...k
add(1,1,i);
p=a[1].k==1?gtp(a[i].k+1):gtp(a[1].k-1);
add(p-1,n-p,i);
}
}
else{
if(a[i].k<i){//?...k(<i)
p=gtp(a[i].k+1);
add(p-1,n-p,i);
}
else{//?...i
if(a[1].k==1){
add(1,1,i);
p=gtp(2);
add(p-1,n-p,i);
}
else{
p=gtp(a[1].k-1);
add(p-1,n-p,i);
}
}
}
ud(i);
}
for(int i=1;i<=4;i++)S[a[i].k]=a[i].s;
dfs(1,2,3,4,0);
printf("%d\n",(int)Ans.size());
for(auto x:Ans)printf("%d %d\n",x.first,x.second);
}
re 0;
}
/*
2
3
1 3 2
5
4 1 2 3 5
*/
}int main(){re FRTMLV::main();}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
input:
2 3 1 3 2 5 4 1 2 3 5
output:
0 6 3 1 1 2 1 1 1 1 1 1 1 1
result:
ok OK in maximum 6 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...
output:
0 1 1 1 1 1 1 8 1 1 1 3 2 2 1 3 1 2 1 1 1 1 1 1