QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211254#962. Thanks to MikeMirzayanovWu_RenWA 1ms3780kbC++141.6kb2023-10-12 13:41:192023-10-12 13:41:20

Judging History

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

  • [2023-10-12 13:41:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3780kb
  • [2023-10-12 13:41:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n,a[20010],b[20010];
int c[20010],le[20010],t=0;
vector<int>tp;
vector<vector<int> >ans;
bool tg=0;
void get(int x){
	tp.clear();
	for(int l=0,r;l<n;l=r){
		r=min(l+(1<<x),n);
		t=0;
		for(int i=l;i<r;i++){
			if(!t||c[t]!=b[i]) c[++t]=b[i],le[t]=1;
			else le[t]++;
		}
		int nw=c[1]==0?1:2;
		for(int i=1;i<=t;i++,nw+=nw&1?1:-1){
			if(i+nw-1>t) nw--;
			if(nw==2) tp.push_back(le[i]+le[i+1]),i++;
			else tp.push_back(le[i]);
		}
	}
	if(tg) reverse(tp.begin(),tp.end());
}
void calc(){
	int sum=0;
	for(int i:tp) sum+=i;
	assert(sum==n);
	if(tp.size()<=1){
		reverse(b,b+n),reverse(a,a+n),tg^=1;
		return;
	}
	int l=0;
	ans.push_back(tp);
	if(tg) reverse(tp.begin(),tp.end()); 
	for(int i:tp){
		reverse(b+l,b+l+i);
		reverse(a+l,a+l+i);
		l+=i;
	}
	tg^=1;
}
bool chk(int x){
	if(tg) reverse(b,b+n);
	for(int l=0,r;l<n;l=r){
		r=min(l+(1<<x),n);
		int ty=0;
		for(int i=l;i<r;i++){
			if(b[i]) ty|=1;
			else if(ty) ty|=2;
		}
		if(ty==3){
			if(tg) reverse(b,b+n);
			return 1;
		}
	}
	if(tg) reverse(b,b+n);
	return 0;
}
void work(int x){
	for(int i=0;i<n;i++) b[i]=(a[i]>>x)&1;
	bool fl=chk(x+1);
	while(fl){
		fl=0;
		get(x+1);
		calc();
		fl=chk(x+1);
	}
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]),a[i]--;
	for(int i=14;i>=0;i--){
		work(i);
	}
	if(tg){
		tp.clear();
		for(int i=0;i<n;i++) tp.push_back(1);
		calc();
	}
	printf("%d\n",ans.size());
	for(auto &j:ans){
		printf("%d ",j.size());
		for(int i:j) printf("%d ",i);puts("");
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3780kb

input:

4
3 1 2 4

output:

4
2 3 1 
2 2 2 
3 1 1 2 
4 1 1 1 1 

result:

ok OK

Test #2:

score: 0
Accepted
time: 1ms
memory: 3720kb

input:

6
6 5 4 3 2 1

output:

3
2 2 4 
2 4 2 
6 1 1 1 1 1 1 

result:

ok OK

Test #3:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

1
1

output:

0

result:

ok OK

Test #4:

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

input:

10
3 8 7 4 6 2 9 10 1 5

output:

6
2 6 4 
2 2 8 
6 1 2 2 2 1 2 
7 2 1 1 2 1 2 1 
5 2 2 1 3 2 
10 1 1 1 1 1 1 1 1 1 1 

result:

wrong answer the permutation is not sorted