QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692098#7619. Make SYSU Great Again Ijacob02Compile Error//C++201.4kb2024-10-31 13:48:382024-10-31 13:48:38

Judging History

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

  • [2024-10-31 13:48:38]
  • 评测
  • [2024-10-31 13:48:38]
  • 提交

answer

#include<iostream>
#include<vector>
#define ll long long
using namespace std;
int n, w;
int a[500005];
int num[15];
int maxn;
int dp[15][500005];
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

answer.code: In function ‘int main()’:
answer.code:32:9: error: ‘memset’ was not declared in this scope
   32 |         memset(dp, 0, sizeof(dp));
      |         ^~~~~~
answer.code:3:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    2 | #include<vector>
  +++ |+#include <cstring>
    3 | #define ll long long