QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567319#4888. Decoding The MessageCryingWA 1ms3876kbC++141.8kb2024-09-16 11:06:022024-09-16 11:06:02

Judging History

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

  • [2024-09-16 11:06:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3876kb
  • [2024-09-16 11:06:02]
  • 提交

answer

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

pr w[MAXM];

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)%mod;
        int fac = 1; if(n >= phi)fac = 0; else for(int i=1;i<=n;i++)fac = fac*i%mod;
        if(n > 5)fac += phi;
        int pw = 1; while(fac--)pw = pw*sum%mod; return pw;
    }
}
namespace T2{
    const int mod = 257,phi = 256;
    int N,buc[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;
        }else return 0;
    }
}

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: 1ms
memory: 3604kb

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: 1ms
memory: 3876kb

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:

54741
54741
59110
59110
514
39321
15420
59110
43570
32896
15420
0
59110
39321
59110
17476
15420
15420
54741
54741
32896
15420
59110
54741
54741
9766
15420
15420
32896
17476
59110
32896
15420
54741
39321
17476
15420
54741
54741
39321
54741
54741
39321
54741
32896
59110
59110
59110
47031
40350
15420
1...

result:

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