QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471813#1436. Split in Setslichenyu_acML 1ms4800kbC++141.2kb2024-07-11 09:12:242024-07-11 09:12:25

Judging History

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

  • [2024-07-11 09:12:25]
  • 评测
  • 测评结果:ML
  • 用时:1ms
  • 内存:4800kb
  • [2024-07-11 09:12:24]
  • 提交

answer

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=1e5+10,mod=1e9+7;

int n,m;
ll a[N],ans;

ll f[N];
void pre_work(int n=N-1){
	f[0]=1;
	for(int i=1;i<=n;i++)f[i]=f[i-1]*i%mod;
}

vector<ll>b;

ll len(ll x){
	ll ret=0;
	while(x)ret++,x>>=1;
	return ret;
}

void solve(int k){
	int cnt=0,Max=0;
	for(auto x:b){
		int now_len=len(x);
		if(now_len==Max)cnt++;
		else if(now_len>Max)Max=now_len,cnt=1;
	}
	if(k==1){
		ll tmp=-1;
		for(auto x:b){
			if(tmp==-1)tmp=x;
			else tmp&=x;
		}
		ans+=tmp;
		return;
	}
	if(cnt==k){
		for(auto x:b)ans+=x;
		return;
	}
	if(cnt==b.size()){
		for(auto &x:b)x-=(1<<(Max-1));
		ans+=k*(1<<(Max-1));
		solve(k);
		return;
	}
	if(cnt<k){
		vector<ll>c;
		for(auto x:b){
			if(x>=(1<<(Max-1)))ans+=x;
			else c.push_back(x);
		}
		b=c;
		solve(k-cnt);
		return;
	}else{
		vector<ll>c;
		ll tmp=-1;
		for(auto x:b){
			if(x>=(1<<(Max-1)))c.push_back(x);
			else{
				if(tmp==-1)tmp=x;
				else tmp&=x;
			}
		}
		c.push_back(tmp);
		b=c;
		solve(k);
		return;
	}
}

int main(){	pre_work();
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),b.push_back(a[i]);
	solve(m);
	printf("%lld %lld\n",ans,f[m]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4552kb

input:

3 2
4 7 5

output:

11 2

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 1ms
memory: 4544kb

input:

4 1
44 47 74 77

output:

8 1

result:

ok 2 tokens

Test #3:

score: 0
Accepted
time: 1ms
memory: 4800kb

input:

4 4
44 47 74 77

output:

242 24

result:

ok 2 tokens

Test #4:

score: -100
Memory Limit Exceeded

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:


result: