QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567388#4888. Decoding The MessageCryingWA 72ms8740kbC++142.7kb2024-09-16 11:39:382024-09-16 11:39:39

Judging History

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

  • [2024-09-16 11:39:39]
  • 评测
  • 测评结果:WA
  • 用时:72ms
  • 内存:8740kb
  • [2024-09-16 11:39:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef array<int,2> pr;
const int MAXN = 30,M = 256;
int T,k,n;

pr w[M+10];

namespace T1{
    const int mod = 255,phi = 128;
    int solve(){
        int sum = 0;
        for(int i=1;i<=M;i++)sum = (sum + 1ll*w[i][0]*w[i][1])%mod;
        int fac = 1; if(n >= phi)fac = 0; else for(int i=1;i<=n;i++)fac = fac*i%phi;
        if(n > 5)fac += phi;
        int pw = 1; while(fac--)pw = pw*sum%mod; return pw;
    }
}
namespace T2{
    const int mod = 257,phi = 256,K = 600;
    int N,buc[mod],now;

    bitset<K> dp[M][mod];

    int solve(){
        N = n/2; //选N个位置base 256,n-N个位置base 1
        memset(buc,0,sizeof buc);
        if(n<12){
            int arr[30] = {}; n = 0;
            for(int i=1;i<=M;i++)while(w[i][0]--)arr[n++] = w[i][1];
            int w = 1; 
            for(int i=1;i<=N;i++)w = w*i%phi;
            for(int i=1;i<=n-N;i++)w = w*i%phi;

            for(int S=0;S<(1<<n);S++){
                int pcnt = __builtin_popcount(S); if(pcnt != N)continue;
                int sum = 0; 
                for(int i=0;i<n;i++){
                    if(S>>i&1)sum = (sum-arr[i]+mod)%mod;
                    else sum = (sum+arr[i])%mod;
                }
                buc[sum] = (buc[sum] + w)%phi;
            }
            int res = 1;
            for(int i=0;i<mod;i++)while(buc[i]--)res = res*i%mod;
            return res;
        }
        now = 0; for(int i=1;i<=M;i++)now = (now + 1ll*w[i][0]*w[i][1])%mod;
        for(int i=1;i<=M;i++)w[i][1] = w[i][1]*2%mod;
        //恰好选出N个人,使得val之和等于now: 此时答案为0,否则为1
        int prec = 0; for(int i=1;i<M;i++)prec += w[i][0]; if(prec >= K)return 0;

        for(int i=0;i<M;i++)for(int j=0;j<mod;j++)dp[i][j].reset();
        dp[0][0][0] = 1;
        for(int i=1;i<M;i++)for(int j=0;j<mod;j++)for(int k=0;k<=w[i][0];k++){
            int nj = (j+k*w[i][1])%mod;
            dp[i][nj] |= (dp[i-1][j]<<k);
        }     
        for(int j=0;j<=mod;j++)for(int k=0;k<=prec;k++)if(dp[M-1][j][k]){
            int r = N-k; if(r>=0 && r<=w[M][0]){
                int nj = (j + 1ll*r*w[M][1])%mod;
                if(nj == now)return 0;
            }
        }   
        return 1;
    }
}

void solve(){
    for(int i=1;i<=M;i++)w[i][0] = 0,w[i][1] = i-1; n = 0;
    cin>>k;
    while(k--){
        int x,c; cin>>x>>c; n += c; w[x+1][0] = c;
    }
    sort(w+1,w+1+M);
    
    int ans_255 = T1::solve(),ans_257 = T2::solve();
    int ans = ans_257; while(ans % 255 != ans_255)ans += 257;
    cout<<ans<<endl;
}

int main(){
    cin>>T;
    while(T--)solve();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3672kb

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: 72ms
memory: 8740kb

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'