QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#234660#5131. Grinding GravelhxhhxhRE 3ms23320kbC++14882b2023-11-01 20:32:442023-11-01 20:32:45

Judging History

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

  • [2023-11-01 20:32:45]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:23320kb
  • [2023-11-01 20:32:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,k,c[111],r[111],t[111],ans,tot,dp[500005][10];
int main(){
	cin>>n>>k;
	for(int i=1,j;i<=n;i++){
		scanf("%d",&j);
		ans+=(j-1)/k;
		c[j%k]++;
	}
	for(int i=1;i<k-i;i++){
		int p=min(c[i],c[k-i]);
		c[i]-=p;
		c[k-i]-=p;
	}
	if(k%2==0) c[k/2]%=2;
	tot=1;
	c[0]=0;
//	for(int i=0;i<k;i++) cout<<setw(12)<<c[i];
//	cout<<endl;
	for(int i=1;i<k;i++) tot*=(c[i]+1);
	memset(dp,0x3f,sizeof(dp));
	dp[tot-1][0]=0;
	for(int i=tot-1;i>0;i--){
		for(int p=0;p<k;p++){
			int x=i;
			for(int j=k-1;j>0;j--) t[j]=r[j]=x%(c[j]+1),x/=(c[j]+1);
			for(int j=1;j<k;j++){
				t[j]--;
				int rx=0;
				for(int l=1;l<k;l++) rx=rx*(c[l]+1)+t[l];
				dp[rx][(p+j)%k]=min(dp[rx][(p+j)%k],dp[i][p]+(p+j>k));
				t[j]++;
			}
//			cout<<setw(12)<<dp[i][p];
		}
//		cout<<endl;
	}
	cout<<dp[0][0]+ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 8
2 4 5 6 7

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2 5
12 13

output:

4

result:

ok single line: '4'

Test #3:

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

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 8
8

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 3ms
memory: 23192kb

input:

4 8
7 7 7 3

output:

2

result:

ok single line: '2'

Test #6:

score: -100
Runtime Error

input:

7 8
7 7 7 7 7 7 6

output:


result: