QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569131#4888. Decoding The Messagestrlen_s_WA 3ms4772kbC++172.4kb2024-09-16 20:43:002024-09-16 20:43:01

Judging History

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

  • [2024-09-16 20:43:01]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:4772kb
  • [2024-09-16 20:43:00]
  • 提交

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][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%=mod3;
  cout<<sum<<'\n';
}
signed main(){
  ios::sync_with_stdio(0);
  cin.tie(0),cout.tie(0);
  cin>>TE;
  while(TE--)work();
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4720kb

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: 3ms
memory: 4772kb

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
48060
15420
22101
...

result:

wrong answer 50th numbers differ - expected: '15420', found: '48060'