QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569153 | #4888. Decoding The Message | strlen_s_ | RE | 3ms | 4716kb | C++17 | 2.3kb | 2024-09-16 20:54:39 | 2024-09-16 20:54:39 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=265,M=555;
ll phi=128,mod1=255,mod2=257,phi2=256,mod3=65535;
ll buk[N];
bitset<M>f[N],g[N];
ll ans1,ans2;
ll dp[2][N][N];
ll ksm(ll a,int b,int mod){
ll res=1;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod,b>>=1;
}
return res;
}
ll calc255(){
ll sum=0,cnt=0,mt=1;
for(int i=0;i<256;i++)cnt+=buk[i],sum=(sum+buk[i]*i)%mod1;
if(cnt>=phi)return (__gcd(sum,mod1)==1?1:ksm(sum,phi,mod1));
if(cnt<=6){
for(int i=1;i<=cnt;i++)mt=mt*i;
return ksm(sum,mt,mod1);
}
for(int i=1;i<=cnt;i++)mt=mt*i%phi;
return ksm(sum,mt+(__gcd(sum,mod1)==1?0:phi),mod1);
}
void upd(int x){
for(int i=0;i<mod2;i++)
g[(i+x)%mod2]=f[i]<<1;
for(int i=0;i<mod2;i++)
f[i]|=g[i];
}
ll calc257(){
ll cnt=0,mx=0,sum=0;
for(int i=0;i<256;i++)cnt+=buk[i],mx=(buk[i]>buk[mx]?i:mx),sum=(sum+buk[i]*i)%mod2;
if(cnt<=12){
memset(dp,0,sizeof(dp));
int o=0;
dp[o][0][0]=1;
for(int i=0;i<256;i++)
for(int j=1;j<=buk[i];j++){
o^=1;
memset(dp[o],0,sizeof(dp[o]));
for(int k=0;k<=cnt/2;k++)
for(int l=0;l<mod2;l++){
dp[o][k+1][(l-i+mod2)%mod2]+=dp[o^1][k][l];
dp[o][k][(l+i)%mod2]+=dp[o^1][k][l];
}
}
if(dp[o][cnt/2][0])return 0;
ll res=1,rt=1;
for(int i=1;i<=cnt/2;i++)res=res*i%phi2;
for(int i=1;i<=cnt-cnt/2;i++)res=res*i%phi2;
for(int i=0;i<mod2;i++)
rt=rt*ksm(i,res*dp[o][cnt/2][i]%phi2,mod2)%mod2;
return rt;
}
if(cnt>=512&&cnt-buk[mx]>=256)return 0;
f[0][0]=1;
for(int i=0;i<256;i++){
if(i==mx)continue;
for(int j=1;j<=buk[i];j++)
upd(i);
}
for(int i=0;i<mod2;i++)
for(int j=0;j<=cnt/2;j++){
if(!f[i][j])continue;
ll lf=cnt/2-j;
if(lf>buk[mx])continue;
if((i+lf*mx)*2%mod2==sum)return 0;
}
return 1;
}
int n;
ll sum;
int TE;
void work(){
memset(buk,0,sizeof(buk));
for(int i=0;i<mod2;i++)f[i]=0;
cin>>n;
for(int i=1,x,y;i<=n;i++)cin>>x>>y,buk[x]=y;
ans1=calc255(),ans2=calc257(),sum=0;
sum+=ans1*ksm(2,phi-1,mod1)*mod2;
sum+=ans2*ksm(255,phi2-1,mod2)*mod1;
sum%=mod3;
cout<<sum<<'\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>TE;
while(TE--)work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4716kb
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: 3ms
memory: 4704kb
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: -100
Runtime Error
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...