QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#510069#1436. Split in SetswullaaaWA 1ms3880kbC++141.4kb2024-08-08 20:56:412024-08-08 20:56:42

Judging History

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

  • [2024-08-08 20:56:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3880kb
  • [2024-08-08 20:56:41]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pli pair<ll,int>
using namespace std;
const int N=1e5+5,MOD=1e9+7;
int n,k,a[N],b[N];
int jc[N],invf[N];
int power(int x,int y){
    int ans=1;
    for(;y;y>>=1,x=1ll*x*x%MOD) if(y&1) ans=1ll*ans*x%MOD;
    return ans;
}
int A(int n,int m){ return 1ll*jc[n]*invf[n-m]%MOD; }
pli dfs(int d,int n,int k){
    if(d<0) return {0,1};
    int cnt=0;
    for(int i=1;i<=n;++i) cnt+=(a[i]>>d&1);
    if(!cnt) return dfs(d-1,n,k);
    if(cnt==n){
        for(int i=1;i<=n;++i) a[i]-=(1<<d);
        auto ans=dfs(d-1,n,k);
        return {ans.first+1ll*(1<<d)*k,ans.second};
    }
    if(cnt<k){
        ll sum=0;
        for(int i=1,j=0;i<=n;++i){
            if(a[i]<(1<<d)) a[++j]=a[i];
            else sum+=a[i];
        }
        auto ans=dfs(d-1,n-cnt,k-cnt);
        return {ans.first+sum,1ll*ans.second*A(k,cnt)%MOD};
    }
    int now=(1<<30)-1,j=0;
    for(int i=1;i<=n;++i){
        if(a[i]>=(1<<d)) a[i]-=(1<<d),a[++j]=a[i];
        else now&=a[i];
    }
    a[++j]=now;
    auto ans=dfs(d-1,j,k);
    return {ans.first+1ll*(1<<d)*(k-1),ans.second};
}
int main(){
    scanf("%d%d",&n,&k);
    jc[0]=1; for(int i=1;i<=n;++i) jc[i]=1ll*jc[i-1]*i%MOD;
    invf[n]=power(jc[n],MOD-2);
    for(int i=n-1;~i;--i) invf[i]=1ll*invf[i+1]*(i+1)%MOD;
    for(int i=1;i<=n;++i) scanf("%d",&a[i]);
    auto ans=dfs(29,n,k);
    printf("%lld %d\n",ans.first,ans.second);
    return 0;
}

详细

Test #1:

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

input:

3 2
4 7 5

output:

11 2

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

4 1
44 47 74 77

output:

8 1

result:

ok 2 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

4 4
44 47 74 77

output:

242 24

result:

ok 2 tokens

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3872kb

input:

1000 975
633065 7087 25267 3940676 618039 1695 2043 728466935 3498 13604984 4 99 119488 151315 12 32 52705062 26815 1902279 33952 480604 390647001 60 1 12566875 7591859 6 119892 7829822 2129 4 11644639 17 33200 5330 338 2 9 6862 3781 148087 57 198 13224999 10493180 1 5755424 216 1757297 210 1002623 ...

output:

35467198613 152712092

result:

wrong answer 2nd words differ - expected: '671056390', found: '152712092'