QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187267#5305. Oscar is All You NeedfstqwqWA 1ms3896kbC++142.6kb2023-09-24 15:53:252023-09-24 15:53:26

Judging History

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

  • [2023-09-24 15:53:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3896kb
  • [2023-09-24 15:53:25]
  • 提交

answer

#include<bits/stdc++.h>
#define N 1100
using namespace std;
typedef vector<int> VI;
typedef pair<int,int> PII;
vector<VI> a,b;
PII ans[N];int top;
void oper(int x,int y,int type=0){
    b=a;int sx=0,sy=0;a.clear();
    for(int i=x+y;i<b.size();i++)a.push_back(b[i]);
    for(int i=x;i<x+y;i++)a.push_back(b[i]),sy+=b[i].size();
    for(int i=0;i<x;i++)a.push_back(b[i]),sx+=b[i].size();
    if(type)top--;
    else ans[++top]=make_pair(sx,sy);
}
VI ls;
void init(){
    b=a;a.clear();
    for(int i=0;i<b.size();i++){
        int j=i;
        while(j+1<b.size() && b[j+1][0]==b[j][0]+b[j].size())j++;
        ls.clear();
        for(int k=i;k<=j;k++){
            for(auto x:b[k])ls.push_back(x);
        }
        i=j;
        a.push_back(ls);
    }
    // for(auto x:a){
    //     for(auto y:x)printf("%d ",y);
    //     printf("\n");
    // }
}
void finit(){
    b=a;a.clear();
    int cnt=4-b.size();
    for(auto x:b){
        a.push_back(x);int id1=a.size()-1,id2=x.size()-1;
        while(id2 && cnt){
            ls.clear();ls.push_back(a[id1][id2]);id2--;cnt--;
            a.push_back(ls);a[id1].pop_back();
        }
    }
}
int n,bel[N];
void solve(){
    int len=a.size();memset(bel,0,sizeof(bel));
    for(int i=0;i<len;i++)bel[a[i][0]]=i;
    for(int i=0;i+1<len;i++){
        if(a[i][0]+a[i].size()>n)continue;
        int x=bel[a[i][0]+a[i].size()];
        if(x>i+2){
            oper(i+1,x-2-i);
            oper(1,len-2);
            return ;
        }
        if(i && x==i+2){
            oper(i,2);
            oper(len-x,1);
            return ;
        }
    }
    oper(len-2,1);
}
bool check(){
    for(int i=0;i<3;i++){
        if(a[i][0]>a[i+1][0])return 0;
    }
    return 1;
}
bool dfs(int dep){
    if(check())return 1;
    if(dep>7)return 0;
    for(int i=1;i<=2;i++){
        for(int j=1;i+j<=3;j++){
            oper(i,j);
            if(dfs(dep+1)==1)return 1;
            oper(4-i-j,j,1);
        }
    }
    return 0;
}
int main(){
    int T;scanf("%d",&T);
    while(T--){
        top=0;a.clear();b.clear();
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            int x;scanf("%d",&x);
            ls.clear();ls.push_back(x);
            a.push_back(ls);
        }
        if(n==3){
            if(a[0][0]>a[2][0])printf("1\n1 1\n");
            else printf("0\n");
        }
        init();
        while(a.size()>4){
            solve();
            init();
        }
        finit();
        dfs(1);
        printf("%d\n",top);
        for(int i=1;i<=top;i++)printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3896kb

input:

2
3
1 3 2
5
4 1 2 3 5

output:

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

result:

wrong answer Jury have smaller lexicographical order