QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131893#5131. Grinding GravelPetroTarnavskyi#WA 1ms3548kbC++171.2kb2023-07-28 19:13:512023-07-28 19:13:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-28 19:13:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3548kb
  • [2023-07-28 19:13:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

map<VI, int> dpT;

int dp(VI cnt, int k){
	int mx = 0;
	FOR(i, 1, k)
		mx = max(mx, cnt[i]);
	if(mx == 0)
		return 0;
	if(dpT.count(cnt))
		return dpT[cnt];
	
	int res = 1e9;
	FOR(i, 1, k){
		if(cnt[i] == 0)
			continue;
		cnt[i]--;
		FOR(j, 1, k){
			if(cnt[j] == 0)
				continue;
			cnt[j]--;
			cnt[(i + j) % k]++;
			
			res = min(res, dp(cnt, k) + (i + j > k));
			
			cnt[(i + j) % k]--;
			cnt[j]++;
		}
		cnt[i]++;
	}
	
	return dpT[cnt] = res;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	int add = 0;
	VI cnt(k);
	FOR(i, 0, n){
		int a;
		cin >> a;
		add += a / k;
		cnt[a % k]++;
	}
	cout << dp(cnt, k) + add << endl;
	
	
	
	


	
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 8
2 4 5 6 7

output:

1

result:

ok single line: '1'

Test #2:

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

input:

2 5
12 13

output:

4

result:

ok single line: '4'

Test #3:

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

input:

1 1
1

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'