QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326983 | #4888. Decoding The Message | zhouhuanyi | WA | 26ms | 4064kb | C++14 | 2.8kb | 2024-02-14 16:59:29 | 2024-02-14 16:59:29 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<bitset>
#define N 514
#define mod 65535
#define mod2 32768
using namespace std;
const int inf=(int)(1e9);
const int inv2=(mod+1)>>1;
const int delta[4]={3,5,17,257};
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 MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int T,k,ans,ans2,a,b,n,cnt[N+1],scnt[N+1],tong[N+1];
bitset<N+1>used[N+1];
bitset<N+1>used2[N+1];
int fast_pow(int a,int b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
int main()
{
int maxn,rt,rcnt,res,ps;
long long rst;
bool op;
T=read();
while (T--)
{
k=read(),n=ans=0,ans2=1;
for (int i=0;i<=255;++i) cnt[i]=0;
for (int i=1;i<=k;++i) cnt[read()]=read();
for (int i=0;i<=255;++i) n+=cnt[i],Adder(ans,1ll*i*cnt[i]%mod);
if (n<=18)
{
ps=0,ans=1;
for (int i=0;i<=255;++i)
for (int j=1;j<=cnt[i];++j)
tong[++ps]=i;
for (int i=0;i<(1<<n);++i)
if (__builtin_popcount(i)==((n+1)>>1))
{
res=0;
for (int j=1;j<=n;++j)
{
if (!((i>>(j-1))&1)) res=MD(res+256*tong[j]%mod);
else Adder(res,tong[j]);
}
ans=1ll*ans*res%mod;
}
rst=1;
for (int i=1;i<=(n>>1);++i) rst*=i;
for (int i=1;i<=((n+1)>>1);++i) rst*=i;
if (rst>=mod2) rst=rst%mod2+mod2;
ans=fast_pow(ans,rst),printf("%d\n",ans);
}
else
{
ans=fast_pow(ans,mod2);
for (int i=0;i<=3;++i)
{
maxn=-inf,rt=res=op=rcnt=0;
for (int j=0;j<delta[i];++j) scnt[j]=0;
for (int j=0;j<=255;++j) scnt[j%delta[i]]+=cnt[j];
for (int j=0;j<delta[i];++j) res=(res+1ll*j*scnt[j])%delta[i];
res=1ll*res*((delta[i]+1)>>1)%delta[i];
for (int j=0;j<delta[i];++j)
if (scnt[j]>maxn)
maxn=scnt[j],rt=j;
for (int j=0;j<delta[i];++j)
if (rt!=j)
rcnt+=scnt[j];
if (min(rcnt,n>>1)>=delta[i]) op=1;
else
{
for (int j=0;j<delta[i];++j) used[j].reset();
used[0][0]=1;
for (int j=0;j<delta[i];++j)
if (rt!=j)
{
for (int k=1;k<=scnt[j];++k)
{
for (int t=0;t<delta[i];++t) used2[(t+j)%delta[i]]=used[t]<<1;
for (int t=0;t<delta[i];++t) used[t]|=used2[t];
}
}
for (int j=0;j<delta[i];++j)
for (int k=0;k<=min(((n+1)>>1),rcnt);++k)
if (used[j][k]&&(1ll*(((n+1)>>1)-k)*rt+j)%delta[i]==res)
op=1;
}
if (op) ans2=1ll*ans2*fast_pow(delta[i],mod2)%mod;
}
a=1ll*MD(ans+ans2)*inv2%mod,b=1ll*MD2(ans-ans2)*inv2%mod,printf("%d\n",MD(a+256ll*b%mod));
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4040kb
input:
5 1 42 1 2 0 1 1 1 1 239 2 2 1 1 2 1 3 1 1 2 2 3 2
output:
42 256 514 1284 61726
result:
ok 5 number(s): "42 256 514 1284 61726"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3772kb
input:
100 1 213 79 1 54 69 1 218 55 1 248 80 1 101 8 1 153 79 1 240 45 1 112 70 1 217 5 1 208 64 1 48 30 1 0 19 1 53 40 1 63 17 1 179 65 1 221 22 1 135 84 1 138 20 1 54 29 1 114 19 1 253 94 1 240 36 1 40 94 1 244 93 1 239 24 1 133 8 1 105 91 1 45 43 1 241 74 1 206 17 1 100 73 1 133 44 1 57 70 1 56 72 1 47...
output:
21846 21846 26215 59110 32896 6426 48060 59110 43570 32896 15420 0 59110 6426 26215 17476 15420 15420 21846 21846 32896 15420 59110 21846 54741 32896 48060 48060 32896 50116 26215 32896 15420 54741 6426 17476 15420 21846 54741 39321 54741 54741 6426 54741 1 59110 59110 26215 54741 15420 15420 22101 ...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
100 1 208 74003161 1 108 37880052 1 102 289342450 1 190 16254190 1 20 507132853 1 1 842472902 1 212 226854721 1 33 797732105 1 213 114087750 1 128 914592259 1 27 779924279 1 203 425018504 1 217 458915584 1 139 710603120 1 226 84538604 1 50 602470204 1 150 228443262 1 48 593328022 1 24 35949157 1 148...
output:
1 54741 0 59110 26215 32896 1 48060 15420 1 21846 32896 32896 59110 32896 59110 15420 54741 21846 1 54741 26215 54741 32896 32896 54741 0 54741 21846 48060 32896 21846 32896 50116 50116 21846 15420 48060 59110 26215 15420 21846 1 54741 21846 48060 15420 54741 17476 48060 54741 6426 54741 59110 54741...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
100 2 14 231169007 169 438746441 1 106 224694504 1 11 18668998 1 94 173751742 1 248 424067991 1 132 301760918 1 192 82611030 1 165 348431335 2 25 205571031 27 312669004 1 244 137616146 2 199 365022194 197 490765328 2 151 270019586 159 158690083 1 169 403261990 1 246 138193758 2 38 426785000 53 20660...
output:
54741 54741 32896 32896 21846 54741 15420 48060 54741 32896 54741 32896 59110 54741 32896 26215 32896 59110 17476 32896 32896 32896 59110 32640 15420 43690 32896 21846 32896 32896 32896 59110 32896 15420 32896 54741 32896 32896 21846 26215 39321 54741 17476 1 32896 21846 48060 32896 32896 32896 1542...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 4028kb
input:
100 19 159 4447181 119 4122592 208 20865102 19 18177591 218 15143881 145 22831007 151 35147071 91 49145857 165 13456608 253 18740477 123 40212709 175 10592471 244 41909532 62 34807087 41 14303940 153 1925365 84 46161946 120 19515674 140 39567667 18 36 6939854 219 19270307 107 26811080 135 44704863 1...
output:
32896 15420 32896 59110 32896 54741 59110 1 32896 32896 32896 1 32896 15420 32896 32896 0 32896 15420 32896 15420 32896 32896 32896 32896 21846 32896 32896 54741 54741 59110 32896 32896 32896 32896 32896 32896 32896 54741 54741 32896 43690 32896 32896 32896 32896 17476 32896 59110 15420 32896 59110 ...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
100 162 143 1143808 192 3810724 189 1037339 105 270668 167 1068188 216 4408992 225 1618501 221 430240 120 3189057 223 2722065 217 1793649 29 3122166 129 249284 245 4125250 89 317643 254 3504072 170 4904459 104 2478836 240 1440277 180 3705854 255 3406356 149 1736411 33 4267429 227 2649591 78 4076525 ...
output:
32896 32896 32896 54741 54741 32896 32896 59110 32896 32896 59110 54741 17476 32896 32896 59110 32896 32896 54741 32896 32896 54741 32896 54741 32896 17476 15420 32896 54741 54741 54741 54741 39321 32896 59110 59110 54741 59110 32896 32896 54741 32896 32896 32896 32896 32896 54741 0 32896 54741 1542...
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
100 2 225 103463954 133 98673573 1 115 229035681 2 72 99532710 56 262010873 1 29 163503969 3 209 190760315 244 3444017 50 194052768 1 64 90518604 3 133 254936162 112 248946806 219 174695931 1 237 93137417 3 151 238090677 19 2534188 145 26960475 3 224 159486758 106 47651522 179 262824676 1 250 540564...
output:
54741 48060 32896 21846 54741 54741 32896 21846 32896 32896 48060 32896 39321 32896 32896 32896 54741 54741 32896 48060 59110 17476 32896 15420 32896 26215 15420 0 32896 32896 15420 32896 32896 32896 54741 54741 48060 15420 15420 59110 32896 32896 32896 32896 32896 54741 21846 32896 54741 1 32896 59...
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 1ms
memory: 4064kb
input:
100 5 9 31874638 121 25059072 79 135500659 252 5862068 235 95284441 5 93 4009689 251 85715731 161 161993061 85 174911893 33 146760588 5 47 131530698 22 19994334 98 99702159 196 78068211 176 86704392 5 116 34106857 39 148267518 79 165442900 16 114763590 0 161252155 5 174 193371329 124 109104737 185 1...
output:
32896 54741 54741 54741 54741 32896 54741 32896 32896 17476 54741 59110 32896 54741 1 54741 54741 15420 43690 1 32896 32896 39321 32896 21846 32896 32896 54741 32896 54741 32896 32896 15420 32896 43690 15420 32896 54741 32896 32896 59110 54741 39321 54741 54741 32896 54741 32896 54741 32896 32896 59...
result:
ok 100 numbers
Test #9:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
100 33 44 18869789 117 8369510 145 3544065 144 3664765 168 1365372 85 12860320 150 13537400 53 8130861 91 4951044 63 8583660 110 17817008 94 4597127 255 7812378 14 17438008 129 16276681 186 5448132 2 11721273 74 6179751 181 10738486 49 19672464 98 19560557 190 14484751 225 5605695 135 9185676 156 92...
output:
32896 32896 54741 17476 59110 32896 32896 32896 59110 59110 32896 54741 32896 32896 32896 32896 32896 32896 54741 32896 32896 59110 54741 54741 32896 21846 54741 54741 32896 54741 43690 32896 32896 32896 32896 32896 17476 32896 32896 54741 32896 54741 32896 59110 59110 32896 32896 32896 32896 32896 ...
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
100 9 113 24641456 211 94030371 136 79996041 181 26478413 180 4010900 84 17453960 5 68850072 112 80595759 207 98062006 5 12 37702784 80 70203355 154 27068043 195 8627370 224 36311167 4 86 89385424 124 55291852 174 21271530 52 37177714 5 153 62356676 6 31133088 249 54379427 158 58660757 17 71472808 2...
output:
54741 32896 59110 54741 54741 32896 54741 32896 6426 32896 32896 54741 32896 32896 32896 54741 39321 54741 54741 32896 54741 32896 59110 54741 17476 54741 54741 59110 43690 32896 32896 32896 54741 32896 32896 32896 54741 39321 32896 39321 54741 54741 32896 32896 54741 32896 21846 32896 17476 32896 3...
result:
ok 100 numbers
Test #11:
score: 0
Accepted
time: 1ms
memory: 4048kb
input:
100 49 144 4682405 99 6524578 55 7445296 28 7539543 113 6780302 169 3932842 214 4675084 245 3630237 87 5943524 15 6686127 29 5394734 211 6289135 146 4999318 152 7976657 115 6464846 217 3716932 104 2332998 75 669827 89 1437466 160 9175851 8 3009996 17 4165901 98 7340466 158 9527493 106 6171697 90 754...
output:
54741 54741 54741 54741 32896 32896 54741 32896 32896 54741 17476 32896 32896 54741 32896 32896 59110 32896 59110 32896 59110 32896 59110 54741 32896 32896 59110 32896 59110 54741 54741 32896 32896 32896 32896 32896 54741 32896 59110 32896 32896 32896 32896 32896 32896 32896 59110 54741 32896 32896 ...
result:
ok 100 numbers
Test #12:
score: 0
Accepted
time: 0ms
memory: 4012kb
input:
100 1 223 1 1 21 1 1 192 1 1 239 1 1 167 1 1 137 1 1 99 1 1 164 1 1 84 1 1 189 1 1 184 1 1 166 1 1 242 1 1 112 1 1 112 1 1 244 1 1 49 1 1 127 1 1 22 1 1 58 1 1 152 1 1 49 1 1 221 1 1 61 1 1 228 1 1 29 1 1 217 1 1 136 1 1 87 1 1 72 1 1 167 1 1 123 1 1 42 1 1 178 1 1 116 1 1 193 1 1 85 1 1 178 1 1 61 ...
output:
223 21 192 239 167 137 99 164 84 189 184 166 242 112 112 244 49 127 22 58 152 49 221 61 228 29 217 136 87 72 167 123 42 178 116 193 85 178 61 163 245 147 153 99 168 5 173 17 156 106 182 109 238 122 229 93 156 121 88 5 50 233 104 127 229 122 123 55 198 185 127 29 27 101 106 142 82 113 159 198 185 64 ...
result:
ok 100 numbers
Test #13:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
100 2 212 2 156 1 2 97 1 251 2 1 8 1 1 98 2 2 198 2 29 1 2 94 1 50 2 2 252 2 9 1 1 48 2 2 17 1 42 2 2 86 2 71 1 2 180 2 141 2 1 83 2 1 13 2 2 201 1 112 2 2 182 1 174 1 1 104 2 2 141 1 109 1 1 56 2 2 103 2 253 2 1 65 1 1 59 1 2 4 2 14 1 1 187 1 1 148 1 2 245 2 240 1 1 211 1 2 145 2 243 1 1 37 1 2 29 ...
output:
2665 11236 8 21331 30940 47881 26994 4626 28561 49149 54741 2056 21331 49555 41056 54484 35470 39064 32896 65 59 60454 187 148 18565 211 54799 37 20935 47089 39835 3000 21331 17611 22374 9601 51366 32896 148 4369 216 39064 28270 40411 1260 21331 52495 128 56461 186 15420 12601 76 28270 55501 43165 6...
result:
ok 100 numbers
Test #14:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
100 2 5 2 24 2 2 51 3 171 3 1 154 3 3 7 3 98 1 232 1 3 87 1 95 1 185 1 1 190 1 3 11 3 77 1 253 1 3 242 2 1 2 247 2 3 152 2 252 2 209 1 3 86 1 223 1 230 3 2 193 2 153 3 2 243 2 196 2 1 39 2 1 98 2 1 193 1 3 175 1 128 3 149 2 3 80 2 236 2 186 3 3 155 3 179 1 6 2 2 110 2 141 2 2 118 2 124 2 3 61 2 120 ...
output:
2056 39441 50199 6561 11824 190 35631 59110 35631 59076 59635 2056 60909 21331 193 15556 44200 48196 32896 32896 26470 39321 125 33916 21846 26215 58566 39064 65289 5 39000 6546 32896 34 160 59076 147 11454 28270 50406 39441 2056 53551 15930 39771 71 58821 25770 61201 15556 39064 28 9154 50661 12850...
result:
ok 100 numbers
Test #15:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
100 4 36 2 119 1 46 1 213 2 4 127 1 176 1 17 3 156 2 3 103 3 7 3 125 2 3 197 2 207 3 65 1 2 178 3 220 1 3 88 2 39 3 195 2 3 145 2 185 4 222 3 1 54 3 2 131 1 81 4 4 156 1 121 3 222 1 8 1 2 225 1 200 2 3 97 3 119 3 43 4 2 225 1 44 2 1 95 4 4 132 3 115 2 125 1 128 2 3 63 1 220 3 174 2 3 251 3 58 3 139 ...
output:
39576 50661 26470 23580 1036 256 34936 20064 2245 41056 8125 26470 61294 28270 1 8721 22101 41056 15420 32896 54741 256 49216 2056 39321 16576 8026 30856 12850 59110 54741 48060 2056 32896 26470 54741 26470 28 60711 23901 21846 32896 63496 8224 59620 256 48196 52701 59110 48060 52701 32571 1 10140 1...
result:
ok 100 numbers
Test #16:
score: 0
Accepted
time: 24ms
memory: 3764kb
input:
100 2 230 2 33 1 3 101 5 218 5 216 4 4 138 2 50 5 148 5 211 1 1 12 5 3 138 5 101 3 124 2 2 51 2 91 1 5 93 4 167 1 157 4 59 1 138 5 3 229 4 227 1 11 2 5 244 5 165 5 142 5 3 1 200 2 5 67 5 15 2 176 3 122 5 50 2 5 69 4 255 2 24 3 228 4 219 5 4 188 3 209 4 121 3 71 1 1 95 1 5 190 5 162 2 158 2 205 3 180...
output:
20179 1 1 46020 50371 39754 1 58600 32896 1 48060 256 95 48060 42790 21846 1 21846 58275 22101 1 1 21846 256 26215 24090 26215 54741 33406 1 54741 59110 56674 1 21846 1 54741 16576 54741 55266 52701 47 18186 21846 1 218 256 54741 87 8736 1 256 32896 34936 54741 21846 36736 32640 50116 16576 256 3235...
result:
ok 100 numbers
Test #17:
score: -100
Wrong Answer
time: 26ms
memory: 4048kb
input:
100 6 12 2 227 5 7 4 83 4 124 3 230 6 6 138 2 58 6 130 6 165 2 30 4 140 3 2 28 5 224 1 3 192 5 207 5 124 4 6 98 6 68 4 66 2 51 3 149 1 81 2 2 238 3 77 3 4 196 2 222 3 146 3 63 2 3 156 4 188 3 74 6 3 44 5 136 6 24 2 4 149 3 165 5 208 2 30 2 6 216 2 24 4 154 5 230 4 242 3 207 1 2 96 2 40 3 2 30 5 172 ...
output:
32896 54741 24736 32896 32896 23070 256 6426 1 1 32896 29511 21846 1 59110 22101 30720 59110 21846 1 1 1 32896 54741 59110 32896 50625 21846 15420 67 15420 63834 37231 32896 34536 32896 1 26215 1 18496 32896 1 26215 1 15420 26215 22101 25164 14415 26331 17460 110 32896 51 3855 24175 54741 48060 3238...
result:
wrong answer 67th numbers differ - expected: '6426', found: '39321'