QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#131893 | #5131. Grinding Gravel | PetroTarnavskyi# | WA | 1ms | 3548kb | C++17 | 1.2kb | 2023-07-28 19:13:51 | 2023-07-28 19:13:52 |
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;
}
詳細信息
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'