QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72863 | #5120. Power of Two | zhouhuanyi | WA | 186ms | 5632kb | C++11 | 3.8kb | 2023-01-19 18:30:33 | 2023-01-19 18:30:35 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cassert>
#define N 65536
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int T,n,x,y,z,rcnt[N+1];
bool used[N+1],vis[N+1];
vector<int>p[N+1];
bitset<N+1>solve(int x)
{
bitset<N+1>st;
st[x]=1;
return st;
}
int main()
{
vector<int>A;
vector<int>B;
vector<int>C;
vector<int>D;
int d,op,opt;
T=read();
while (T--)
{
n=read(),x=read(),z=read(),y=read(),A.clear(),B.clear(),C.clear(),D.clear(),opt=0;
for (int i=0;i<=n-1;++i) rcnt[i]=used[i]=vis[i]=0;
for (int i=1;i<=n;++i) d=read(),rcnt[d]++;
if (x)
{
if (z)
{
for (int i=n-1;i>=0;--i)
if (rcnt[i])
{
if (rcnt[i]>=2&&z) z--,D.push_back(i),rcnt[i]--,used[i]=vis[i]=1;
else if (y) y--,C.push_back(i),rcnt[i]--,used[i]=1;
else if (z) z--,D.push_back(i),rcnt[i]--,used[i]=vis[i]=1;
while (rcnt[i])
{
if (x) x--,B.push_back(i),rcnt[i]--;
else if (y) y--,C.push_back(i),rcnt[i]--;
else z--,D.push_back(i),rcnt[i]--;
}
}
for (int i=0;i<=n-1;++i) rcnt[i]=0;
for (int i=0;i<C.size();++i) rcnt[C[i]]++;
for (int i=0;i<=n-1;++i)
if (rcnt[i]&&!(rcnt[i]&1)&&!vis[i])
A.push_back(i),rcnt[i]--;
C.clear();
for (int i=0;i<=n-1;++i)
for (int j=1;j<=rcnt[i];++j)
C.push_back(i);
}
else
{
for (int i=n-1;i>=0;--i)
if (rcnt[i]&&y)
y--,C.push_back(i),rcnt[i]--,used[i]=1;
for (int i=0;i<=n-1;++i)
if (rcnt[i]&&x)
x--,B.push_back(i),rcnt[i]--;
for (int i=0;i<=n-1;++i)
while (rcnt[i])
{
if (x) x--,B.push_back(i),rcnt[i]--;
else y--,C.push_back(i),rcnt[i]--;
}
op=1;
for (int i=1;i<B.size();++i) op&=(B[0]==B[i]);
for (int i=0;i<=n-1;++i) rcnt[i]=0;
for (int i=0;i<C.size();++i) rcnt[C[i]]++;
if (op&&(!(rcnt[B[0]]&1)))
{
if (B.size()==1)
{
op=0;
for (int i=0;i<=n-1;++i)
if (i!=B[0]&&rcnt[i]&&!(rcnt[i]&1))
{
rcnt[i]--,rcnt[B[0]]++,B.pop_back(),B.push_back(i),op=1;
break;
}
if (!op)
{
for (int i=0;i<B[0];++i)
if (rcnt[i])
{
rcnt[i]--,rcnt[B[0]]++,B.pop_back(),B.push_back(i),used[i]=0,op=1;
break;
}
}
if (!op) used[B[0]]=0;
}
else B.pop_back(),opt=1;
}
for (int i=0;i<=n-1;++i)
if (rcnt[i]&&!(rcnt[i]&1))
A.push_back(i),rcnt[i]--;
C.clear();
for (int i=0;i<=n-1;++i)
for (int j=1;j<=rcnt[i];++j)
C.push_back(i);
}
}
else
{
for (int i=n-1;i>=0;--i)
if (rcnt[i])
{
used[i]=1;
if (!(rcnt[i]&1))
{
if (z) D.push_back(i),rcnt[i]--,z--;
else used[i]=0;
}
}
for (int i=n-1;i>=0;--i)
while (rcnt[i]&&z)
D.push_back(i),rcnt[i]--,z--;
for (int i=0;i<=n-1;++i)
for (int j=1;j<=rcnt[i];++j)
C.push_back(i);
}
for (int i=n-1;i>=0;--i) printf("%d",used[i]);
puts("");
if (opt) printf("&");
for (int i=0;i<A.size();++i) printf("^");
for (int i=0;i<B.size();++i) printf("&");
for (int i=0;i<C.size();++i) printf("^");
for (int i=0;i<D.size();++i) printf("|");
puts("");
if (opt) printf("%d ",B[0]);
for (int i=0;i<A.size();++i) printf("%d ",A[i]);
for (int i=0;i<B.size();++i) printf("%d ",B[i]);
for (int i=0;i<C.size();++i) printf("%d ",C[i]);
for (int i=0;i<D.size();++i) printf("%d ",D[i]);
puts("");
/*
bitset<N+1>st;
for (int i=0;i<A.size();++i) st^=solve(A[i]);
for (int i=0;i<B.size();++i) st&=solve(B[i]);
for (int i=0;i<C.size();++i) st^=solve(C[i]);
for (int i=0;i<D.size();++i) st|=solve(D[i]);
for (int i=0;i<=n-1;++i) assert(st[i]==used[i]);
*/
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5236kb
input:
4 4 3 0 1 1 0 1 0 4 1 0 3 1 0 1 0 8 0 2 6 1 5 5 7 1 5 5 7 8 0 0 8 1 5 5 7 1 5 5 7
output:
0010 &&&^ 0 1 0 1 0011 ^&^^ 1 0 0 1 10100000 ^^^^^^|| 1 1 5 5 5 7 7 5 00000000 ^^^^^^^^ 1 1 5 5 5 5 7 7
result:
ok ok the answer is correct (4 test cases)
Test #2:
score: 0
Accepted
time: 186ms
memory: 5632kb
input:
16 65511 1 1 65509 42389 52308 9452 29149 28980 48173 38152 51625 29991 48293 12319 38611 47245 11954 45410 33185 30976 56806 18986 35564 25430 48493 26311 19090 42172 33403 62406 15847 51266 33712 53139 15610 50006 62298 28716 19191 3057 35733 12331 14483 9604 16610 18534 32110 35673 5239 31310 279...
output:
011100011111111101111001001110101111111101101101011111011100100111011110101110111110111001110100111101110110111100111101101101111110110101011011111111011111110111000110010000010111011100111101111101111111010001010110100100000110101000001011101011001111110011101111010011101101111010101110011101111110...
result:
ok ok the answer is correct (16 test cases)
Test #3:
score: 0
Accepted
time: 1ms
memory: 5240kb
input:
3 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0
output:
1 ^ 0 1 | 0 0 & 0
result:
ok ok the answer is correct (3 test cases)
Test #4:
score: 0
Accepted
time: 3ms
memory: 5136kb
input:
12 2 0 0 2 0 0 2 0 1 1 0 0 2 0 2 0 0 0 2 1 0 1 0 0 2 1 1 0 0 0 2 2 0 0 0 0 2 0 0 2 0 1 2 0 1 1 0 1 2 0 2 0 0 1 2 1 0 1 0 1 2 1 1 0 0 1 2 2 0 0 0 1
output:
00 ^^ 0 0 01 ^| 0 0 01 || 0 0 01 &^ 0 0 01 &| 0 0 00 && 0 0 11 ^^ 0 1 11 ^| 0 1 11 || 1 0 10 &^ 0 1 10 &| 0 1 00 && 0 1
result:
ok ok the answer is correct (12 test cases)
Test #5:
score: 0
Accepted
time: 3ms
memory: 5136kb
input:
40 3 0 0 3 0 0 0 3 0 1 2 0 0 0 3 0 2 1 0 0 0 3 0 3 0 0 0 0 3 1 0 2 0 0 0 3 1 1 1 0 0 0 3 1 2 0 0 0 0 3 2 0 1 0 0 0 3 2 1 0 0 0 0 3 3 0 0 0 0 0 3 0 0 3 0 1 1 3 0 1 2 0 1 1 3 0 2 1 0 1 1 3 0 3 0 0 1 1 3 1 0 2 0 1 1 3 1 1 1 0 1 1 3 1 2 0 0 1 1 3 2 0 1 0 1 1 3 2 1 0 0 1 1 3 3 0 0 0 1 1 3 0 0 3 0 0 1 3 0...
output:
001 ^^^ 0 0 0 001 ^^| 0 0 0 001 ^|| 0 0 0 001 ||| 0 0 0 000 ^&^ 0 0 0 001 &^| 0 0 0 001 &|| 0 0 0 001 &&^ 0 0 0 001 &&| 0 0 0 000 &&& 0 0 0 001 ^^^ 0 1 1 011 ^^| 0 1 1 011 ^|| 0 1 1 011 ||| 1 1 0 011 &^^ 1 0 1 011 &^| 1 0 1 011 &|| 1 1 0 010 &&^ 0 1 1 010 &&| 1 0 1 000 &&& 0 1 1 ...
result:
ok ok the answer is correct (40 test cases)
Test #6:
score: -100
Wrong Answer
time: 3ms
memory: 5212kb
input:
120 4 0 0 4 0 0 0 0 4 0 1 3 0 0 0 0 4 0 2 2 0 0 0 0 4 0 3 1 0 0 0 0 4 0 4 0 0 0 0 0 4 1 0 3 0 0 0 0 4 1 1 2 0 0 0 0 4 1 2 1 0 0 0 0 4 1 3 0 0 0 0 0 4 2 0 2 0 0 0 0 4 2 1 1 0 0 0 0 4 2 2 0 0 0 0 0 4 3 0 1 0 0 0 0 4 3 1 0 0 0 0 0 4 4 0 0 0 0 0 0 4 0 0 4 1 1 0 1 4 0 1 3 1 1 0 1 4 0 2 2 1 1 0 1 4 0 3 1 ...
output:
0000 ^^^^ 0 0 0 0 0001 ^^^| 0 0 0 0 0001 ^^|| 0 0 0 0 0001 ^||| 0 0 0 0 0001 |||| 0 0 0 0 0001 &^^^ 0 0 0 0 0001 &^^| 0 0 0 0 0001 &^|| 0 0 0 0 0001 &||| 0 0 0 0 0001 &^&^ 0 0 0 0 0001 &&^| 0 0 0 0 0001 &&|| 0 0 0 0 0001 &&&^ 0 0 0 0 0001 &&&| 0 0 0 0 0000 &&&& 0 0 0 0 0011 ^^^^ 0 1 1...
result:
wrong answer wrong construction (test case 10)