QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#567408 | #4888. Decoding The Message | Crying | WA | 0ms | 3864kb | C++14 | 2.7kb | 2024-09-16 11:49:06 | 2024-09-16 11:49:07 |
Judging History
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;
}
assert(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();
cout<<ans_257<<endl;
int ans = ans_257; while(ans % 255 != ans_255)ans += 257;
cout<<ans<<endl;
}
int main(){
cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3864kb
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 42 256 256 0 514 256 1284 46 61726
result:
wrong answer 2nd numbers differ - expected: '256', found: '42'