QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567412#4888. Decoding The MessageCryingWA 0ms3860kbC++142.7kb2024-09-16 11:49:532024-09-16 11:49:54

Judging History

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

  • [2024-09-16 11:49:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3860kb
  • [2024-09-16 11:49:53]
  • 提交

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;
        }
        cout<<"done\n"; exit(0);
        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: 3860kb

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: 0ms
memory: 3548kb

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:

done

result:

wrong output format Expected integer, but "done" found