QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117827#962. Thanks to MikeMirzayanov1kriWA 1ms3696kbC++171.5kb2023-07-02 09:57:412023-07-02 09:57:45

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-02 09:57:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3696kb
  • [2023-07-02 09:57:41]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n,c[20005];
vector<vector<int>> ans;
vector<vector<int>> work(int l,int r,int w){
	vector<vector<int>> ans(w+1);
	for (int i=0;i<=w;i++){
		int last=l,o=0;
		if ((c[l]>>w)&1)o=1;
		vector<pair<int,int>> qwq;
		for (int j=l;j<=r;j++){
			if ((c[j]>>w)&1)continue;
			int k=j;
			while(k<r&&((c[k+1]>>w)&1)==((c[j]>>w)&1))k++;
			if (o==0)last=k+1;
			else qwq.push_back(make_pair(last,k));
			o^=1;
			j=k;
		}
		last=l;
		for (int j=0;j<(int)qwq.size();j++){
			for (int k=last;k<qwq[j].first;k++)ans[i].push_back(1);
			ans[i].push_back(qwq[j].second-qwq[j].first+1);
			for (int p=qwq[j].first,q=qwq[j].second;p<q;p++,q--)swap(c[p],c[q]);
			last=qwq[j].second+1;
		}
		for (int j=last;j<=r;j++)ans[i].push_back(1);
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&c[i]);
	int t=0;
	for (int i=14;i>=0;i--){
		for (int l=1;l<=n;l++){
			int r=l;
			while(r<n&&((c[r+1]>>(i+1))==(c[l]>>(i+1))))r++;
			vector<vector<int>> qwq=work(l,r,i);
			for (int p=0;p<=i;p++){
				if (l==1)ans.push_back(qwq[p]);
				else{
					for (int q=0;q<(int)qwq[p].size();q++)
						ans[t+p].push_back(qwq[p][q]);
				}
			}
			l=r;
		}
		t+=i+1;
	}
	for (int i=0;i<t;i++)
		if (i&1)reverse(ans[i].begin(),ans[i].end());
	printf("%d\n",t);
	for (int i=0;i<t;i++){
		printf("%d ",ans[i].size());
		for (int j=0;j<(int)ans[i].size();j++)printf("%d ",ans[i][j]);
		printf("\n");
	} 
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
3 1 2 4

output:

120
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 
4 1 1 1 1 ...

result:

ok OK

Test #2:

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

input:

6
6 5 4 3 2 1

output:

120
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1 1 
6 1 1 1 1 1...

result:

wrong answer Integer 1 violates the range [2, 6]