QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#187293#5305. Oscar is All You NeedfstqwqWA 0ms3928kbC++144.1kb2023-09-24 16:08:202023-09-24 16:08:20

Judging History

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

  • [2023-09-24 16:08:20]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3928kb
  • [2023-09-24 16:08:20]
  • 提交

answer

#include<bits/stdc++.h>
#define N 1100
#define NN 2100
using namespace std;
typedef pair<int,int> PII;
int n,m;
int a[N],b[N],c[N];PII d[N];
bool v[N];
void init(){
    m=0;
    for(int i=1;i<=n;i++)b[a[i]]=i;
    for(int i=1;i<=n;i++){
        int x=b[i],y=x;if(x!=1 && a[x]-1==a[x-1])continue;
        while(y<n && a[y+1]==a[y]+1)y++;
        d[++m]=make_pair(x,y);c[x]=m;
    }
    m=0;
    for(int i=1;i<=n;i++){
        if(i==1 || a[i]!=a[i-1]+1)c[++m]=c[i];
    }
}
PII zans[N];int anstop;
int ff[N];
void oper1(int x,int y){
    zans[++anstop]=make_pair(x,n-x-y);
    int zlen=0;
    for(int i=x+y+1;i<=n;i++)ff[++zlen]=a[i];
    for(int i=x+1;i<=x+y;i++)ff[++zlen]=a[i];
    for(int i=1;i<=x;i++)ff[++zlen]=a[i];
    for(int i=1;i<=n;i++)a[i]=ff[i];
    return ;
}
void oper2(int x,int y){
    int xx=0,yy=0;
    for(int i=1;i<=x;i++)xx+=d[c[i]].second-d[c[i]].first+1;
    for(int i=x+1;i<=x+y;i++)yy+=d[c[i]].second-d[c[i]].first+1;
    oper1(xx,yy);
    
    int zlen=0;
    for(int i=x+y+1;i<=m;i++)ff[++zlen]=c[i];
    for(int i=x+1;i<=x+y;i++)ff[++zlen]=c[i];
    for(int i=1;i<=x;i++)ff[++zlen]=c[i];
    for(int i=1;i<=m;i++)c[i]=ff[i];
}
int zjj[N];
void solve(){
    for(int i=1;i<=m;i++)zjj[c[i]]=i;
    for(int i=1;i<m;i++){
        int x=zjj[i],y=zjj[i+1];
        if(y-x>=2){
            oper2(x,y-2-x);
            oper2(1,m-2);
            return ;
        }
        else if(y>x && x>=2){
            oper2(x-1,1);
            oper2(1,m-2);
            return ;
        }
    }
    if(c[m]==c[m-1]-1){oper2(m-2,1);}
}

namespace DFS{
    PII fv[N];int ftop;
    int fuck[N];
    int ffa[N],ffb[N];
    void finit(){
        ftop=0;int cnt=m;
        for(int i=1;i<=m;i++){
            while(ftop+m-i+1<4 && d[i].first<d[i].second)fv[++ftop]=make_pair(d[i].first,d[i].first),d[i].first++;
            fv[++ftop]=d[i];
        }
        memset(fuck,0,sizeof(fuck));
        for(int i=1;i<=4;i++)fuck[fv[i].first]=i,d[i]=fv[i];
        m=0;
        for(int i=1;i<=n;i++){
            if(fuck[i])c[++m]=fuck[i];
        }
        for(int i=1;i<=4;i++)ffa[i]=c[i];
    }
    bool check(){
        for(int i=1;i<=4;i++){
            if(ffa[i]!=i)return 0;
        }
        return 1;
    }
    void Zjj(int x,int y){
        int len=0;
        for(int i=x+y+1;i<=4;i++)ffb[++len]=ffa[i];
        for(int i=x+1;i<=x+y;i++)ffb[++len]=ffa[i];
        for(int i=1;i<=x;i++)ffb[++len]=ffa[i];
        for(int i=1;i<=4;i++)ffa[i]=ffb[i];
    }
    PII ans[N];int tot;
    
    void add(int x,int y){
        ans[++tot]=make_pair(x,y);
        Zjj(x,y);
    }
    void del(){
        Zjj(4-ans[tot].first-ans[tot].second,ans[tot].second);
        tot--;
    }
    bool Fuck(){
        if(tot>7)return 0;
        if(check()==1){
            for(int i=1;i<=tot;i++)oper2(ans[i].first,ans[i].second);
            return 1;
        }
        for(int i=1;i<=2;i++){
            for(int j=1;i+j<=3;j++){
                add(i,j);
                if(Fuck()==1){
                    del();
                    return 1;
                }
                del();
            }
        }
        return 0;
    }
}
int main(){
    int T;scanf("%d",&T);
    while(T--){
        
        anstop=DFS::tot=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)scanf("%d",&a[i]);
        if(n==3){
            if(a[3]<a[1])printf("1\n1 1\n");
            else printf("0\n");
            continue;
        }
        init();
        while(m>=5){
            solve();
            init();
            // printf("%d\n",anstop);
            // for(int i=1;i<=n;i++)printf("%d ",a[i]);
            // printf("\n");
        }
        DFS::finit();
        // printf("%d\n",m);
        // for(int i=1;i<=m;i++)printf("%d(%d %d) ",c[i],d[i].first,d[i].second);
        // printf("\n");
        // for(int i=1;i<=m;i++)printf("%d ",DFS::ffa[i]);
        // printf("\n");
        DFS::Fuck();
        printf("%d\n",anstop);
        for(int i=1;i<=anstop;i++)printf("%d %d\n",zans[i].first,zans[i].second);
    }
   return 0;
}

詳細信息

Test #1:

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

input:

2
3
1 3 2
5
4 1 2 3 5

output:

0
6
1 3
2 2
1 3
1 2
2 1
1 1

result:

ok OK in maximum 6 operations

Test #2:

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

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

result:

wrong answer x+y is greater than n