QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#569075#4888. Decoding The Messagestrlen_s_WA 2ms4760kbC++172.2kb2024-09-16 20:20:422024-09-16 20:20:43

Judging History

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

  • [2024-09-16 20:20:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4760kb
  • [2024-09-16 20:20:42]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=265,M=555,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,const 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 1;
  for(int i=1;i<=cnt;i++)mt=mt*i%phi;
  return ksm(sum,mt,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<=11){
    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][k+1][(l-i+mod2)%mod2]+dp[o^1][k][l])%phi2;
            dp[o][k][(l+i)%mod2]=(dp[o][k][(l+i)%mod2]+dp[o^1][k][l])%phi2;
          }
      }
    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%=65535;
  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: 1ms
memory: 4760kb

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: -100
Wrong Answer
time: 2ms
memory: 4744kb

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:

1
1
1
32896
32896
1
1
32896
43570
32896
32896
32896
32896
1
1
32896
32896
32896
1
1
32896
32896
32896
1
32896
32896
1
1
32896
1
1
32896
32896
32896
1
32896
32896
1
32896
32896
32896
32896
1
32896
1
32896
32896
1
32896
1
32896
256
1
32896
32896
1
1
1
1
32896
32896
239
32896
1
1
32896
1
1
32896
1
1
1
...

result:

wrong answer 1st numbers differ - expected: '21846', found: '1'