QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#131891 | #5131. Grinding Gravel | PetroTarnavskyi# | WA | 1ms | 3584kb | C++17 | 1.4kb | 2023-07-28 19:09:41 | 2023-07-28 19:09:43 |
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){
FOR(i, 1, k){
if(i == k - i)
cnt[i] %= 2;
if(i >= k - i)
break;
int mn = min(cnt[i], cnt[k - i]);
cnt[i] -= mn;
cnt[k - i] -= mn;
}
/*
FOR(i, 0, k)
cout << cnt[i] << " ";
cout << endl;
*/
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) + 1);
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
5 8 2 4 5 6 7
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
2 5 12 13
output:
4
result:
ok single line: '4'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3480kb
input:
1 1 1
output:
1
result:
wrong answer 1st lines differ - expected: '0', found: '1'