QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#131892 | #5131. Grinding Gravel | PetroTarnavskyi# | WA | 1ms | 3468kb | C++17 | 1.2kb | 2023-07-28 19:11:34 | 2023-07-28 19:11:35 |
Judging History
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: 1ms
memory: 3460kb
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: 3468kb
input:
1 1 1
output:
1
result:
wrong answer 1st lines differ - expected: '0', found: '1'