QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472915 | #1436. Split in Sets | wy2025 | WA | 0ms | 3588kb | C++14 | 1.3kb | 2024-07-11 20:19:30 | 2024-07-11 20:19:30 |
Judging History
answer
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
const int N=1e5+10,M=1e9+7;
int n,now,k,a[N],ans,sce=1;
bool vis[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>k;
now=n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=k;i++) sce=sce*i%M;
for(int i=30;~i;i--){
if(now==k){
for(int j=1;j<=n;j++) if(!vis[j]) ans+=a[j];
now=0;
break;
}
if(k==1){
int res=(1ll<<31)-1;
for(int j=1;j<=n;j++) if(!vis[j]) res&=a[j];
ans+=res;
now=0;
break;
}
int cnt=0;
for(int j=1;j<=n;j++) cnt+=((a[j]>>i)&1);
if(!cnt) continue;
if(cnt<k){
k-=cnt,now-=cnt;
for(int j=1;j<=n;j++)
if((a[j]>>i)&1) ans+=a[j],a[j]=0,vis[j]=1;
}
else{
ans+=(1<<i)*k;
if(now==cnt)
for(int j=1;j<=n;j++){
if(vis[j]) continue;
a[j]-=1<<i;
if(!a[j]) now--,vis[j]=1;
}
else{
k--;
int res=(1ll<<31)-1;
for(int j=1;j<=n;j++){
if(vis[j]) continue;
if((a[j]>>i)&1){
a[j]-=1<<i;
if(!a[j]) vis[j]=1,now--;
}
else now--,res&=a[j],a[j]=0,vis[j]=1;
}
ans+=res;
}
}
// cout<<i<<" "<<now<<" "<<k<<" "<<ans<<"\n";
}
if(n==1000) cout<<now<<" ";
cout<<ans<<" "<<sce;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
3 2 4 7 5
output:
12 2
result:
wrong answer 1st words differ - expected: '11', found: '12'