QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#692102 | #7619. Make SYSU Great Again I | jacob02 | TL | 0ms | 0kb | C++20 | 1.4kb | 2024-10-31 13:49:11 | 2024-10-31 13:49:11 |
answer
#include<iostream>
#include<vector>
#include<cstring>
#define ll long long
using namespace std;
int n, w;
int a[50005];
int num[15];
int maxn;
int dp[15][50005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> a[i];
num[a[i]]++;
maxn = max(maxn, a[i]);
}
int cnt = 0;
vector<int> nn;
nn.push_back(0);
for (int i = 1; i <= maxn; i++) {
if (num[i])nn.push_back(num[i]);
}
int ans = 0;
maxn = nn.size() - 1;
// cout<<maxn<<"?";
while (cnt <= maxn) {
ans++;
int now = maxn - cnt;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= now; i++) {
for (int j = w; j >= 1; j--) {
if (j >= nn[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - nn[i]] + 1);
}
else {
dp[i][j] = dp[i - 1][j];
}
}
}
int j = w;
vector<int> tp;
for (int i = now; i >= 1; i--) {
if (dp[i][j] != dp[i - 1][j]) {
tp.push_back(i);
j = j - nn[i];
}
}
for (int i = 0; i < tp.size(); i++) {
nn.erase(nn.begin() + tp[i], nn.begin() + tp[i] + 1);
}
cnt += tp.size();
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
3 6