QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53646 | #4888. Decoding The Message | KING_UT# | WA | 9ms | 3852kb | C++20 | 2.6kb | 2022-10-05 16:29:33 | 2022-10-05 16:29:33 |
Judging History
answer
#include <bits/stdc++.h>
#define MX 256
#define PR 257
using namespace std;
typedef long long int ll;
const uint mod=65535;
struct mint{
uint v;
mint(ll vv=0){s(vv%mod+mod);}
mint&s(uint vv){
v=vv<mod?vv:vv-mod;
return *this;
}
mint operator-()const{return mint()-*this;}
mint&operator+=(const mint&r){return s(v+r.v);}
mint&operator-=(const mint&r){return s(v+mod-r.v);}
mint&operator*=(const mint&r){v=(unsigned ll)v*r.v%mod;return *this;}
mint&operator/=(const mint&r){return *this*=r.inv();}
mint operator+(const mint&r)const{return mint(*this)+=r;}
mint operator-(const mint&r)const{return mint(*this)-=r;}
mint operator*(const mint&r)const{return mint(*this)*=r;}
mint operator/(const mint&r)const{return mint(*this)/=r;}
mint pow(ll n)const{
if(n<0)return inv().pow(-n);
mint res(1),x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
mint inv()const{return pow(mod-2);}
};
int cnt[MX];
bitset<PR> dp[2*PR];
void solve(){
int k2;
scanf("%d",&k2);
memset(cnt,0,sizeof(cnt));
int n=0;
for(int i=0;i<k2;i++){
int a,b;
scanf("%d%d",&a,&b);
cnt[a]=b;
n+=b;
}
if(n<=15){
vector <int> vec;
for(int i=0;i<MX;i++){
for(int j=0;j<cnt[i];j++){
vec.push_back(i);
}
}
ll fac=1;
for(int i=1;i<=n/2;i++) fac*=i;
for(int i=1;i<=(n+1)/2;i++) fac*=i;
mint ret=1;
for(int S=0;S<1<<n;S++){
int c=0;
for(int i=0;i<n;i++) if(S>>i&1) c++;
if(c!=n/2) continue;
mint score=0;
for(int i=0;i<n;i++){
if(S>>i&1) score+=vec[i]*256;
else score+=vec[i];
}
ret*=score.pow(fac);
}
printf("%u\n",ret.v);
} else{
mint sum=0;
for(int i=0;i<MX;i++){
sum+=(ll) i*cnt[i];
}
int mx=0,p=0;
for(int i=0;i<MX;i++){
if(mx<cnt[i]){
mx=cnt[i];
p=i;
}
}
bool up=false;
if(n-mx<PR*2){
int z=min(n/2,n-mx);
for(int i=0;i<=z;i++) dp[i].reset();
dp[0][0]=1;
for(int i=0;i<MX;i++){
if(i==p) continue;
for(int j=0;j<cnt[i];j++){
for(int k=z;k>0;k--){
dp[k]|=dp[k-1]<<i;
if(i>0) dp[k]|=dp[k-1]>>(PR-i);
}
}
}
for(int i=0;i<=z;i++){
for(int j=0;j<PR;j++){
if(dp[i][j]&&i+mx>=n/2){
ll cur=(j+(ll) (n/2-i)*p)%PR;
if(cur*2==sum.v%PR){
up=true;
}
}
}
}
} else up=true;
for(int ans=0;ans<mod;ans++){
bool ok=true;
for(int k=0;k<=3;k++){
int c=(1<<(1<<k))+1;
if(k!=3){
if(sum.v%c==0){
if(ans%c!=0) ok=false;
} else{
if(ans%c!=1) ok=false;
}
} else{
if(up){
if(ans%c!=0) ok=false;
} else{
if(ans%c!=1) ok=false;
}
}
}
if(ok){
printf("%d\n",ans);
}
}
}
}
int main(){
int T;
scanf("%d",&T);
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3688kb
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: 9ms
memory: 3852kb
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 26215 32896 6426 48060 59110 43570 1 48060 0 59110 6426 26215 17476 15420 15420 21846 21846 32896 48060 59110 21846 54741 32896 48060 48060 1 50116 26215 32896 48060 21846 6426 17476 15420 21846 21846 6426 21846 54741 6426 21846 1 26215 59110 26215 54741 15420 15420 22101 26215 591...
result:
wrong answer 4th numbers differ - expected: '59110', found: '26215'