QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187277 | #5305. Oscar is All You Need | fstqwq | WA | 2ms | 4080kb | C++14 | 2.7kb | 2023-09-24 16:00:07 | 2023-09-24 16:00:08 |
Judging History
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;
int n,bel[N];
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,n-sy-sx);
}
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();
}
}
}
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");
continue;
}
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: 100
Accepted
time: 0ms
memory: 3788kb
input:
2 3 1 3 2 5 4 1 2 3 5
output:
0 6 1 2 1 3 2 2 1 3 3 1 1 2
result:
ok OK in maximum 6 operations
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 4080kb
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 7 2 2 1 3 1 2 1 3 3 1 1 1 1 3 21 1 2 1 1 3 7 1 1 2 4 1 2 5 6 1 1 3 8 1 1 8 3 2 1 2 6 4 2 5 5 1 7 2 5 4 2 2 9 5 2 6 5 67 1 22 1 1 2 28 1 2 3 32 1 3 4 3 1 4 5 12 1 5 6 13 1 6 7 26 1 7 8 18 1 8 9 8 1 9 10 11 1 10 11 13 1 11 12 17 1 12 14 13 1 1 2 23 1 2 3 29 1 3 4 14 1 4 5 21 1 5 6 16 1 6...
result:
wrong answer Jury have smaller lexicographical order