QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117827 | #962. Thanks to MikeMirzayanov | 1kri | WA | 1ms | 3696kb | C++17 | 1.5kb | 2023-07-02 09:57:41 | 2023-07-02 09:57:45 |
Judging History
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]