QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692102#7619. Make SYSU Great Again Ijacob02TL 0ms0kbC++201.4kb2024-10-31 13:49:112024-10-31 13:49:11

Judging History

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

  • [2024-10-31 13:49:11]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [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

output:


result: