QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#454782#8768. Arrested Developmentscau_ly#Compile Error//C++144.6kb2024-06-25 13:47:402024-06-25 13:47:42

Judging History

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

  • [2024-06-25 13:47:42]
  • 评测
  • [2024-06-25 13:47:40]
  • 提交

answer

#include <cstdio>
#include <iostream>
#include <set>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 100005;
const int MOD = 998244353;
const int MAX_VAL = N * 100;

int n;
struct Task {
    int a, b;
};

int dp[2][2][50 * N];
struct DpState {
    int i, j, k;
    DpState(int _i, int _j, int _k) {
        i = _i;
        j = _j;
        k = _k;
    }
};
queue<DpState> que;
set<int> state_set;

int main() {
    memset(dp, MAX_VAL, sizeof(dp));
    while (cin >> n) {
        Task task[100];
        for (int i = 1; i <= n; i++) {
            scanf("%d%d", &task[i].a, &task[i].b);
        }

        int ans = MAX_VAL;
        state_set.clear();
        que.push(DpState(0, 0, 0));
        dp[0][0][0] = 0;
        state_set.insert(0);
        while (!que.empty()) {
            DpState state = que.front();
            que.pop();
            int i = state.i, j = state.j, k = state.k;
            if (i == n) {
                ans = min(ans, dp[i & 1][j][k]);
                continue;
            }
            if (j == 0) {
                // use a
                {
                    int _i = i + 1, _j = j, _k = k + task[i + 1].a;
                    int state = (_i << 25) | (_j << 23) | _k;
                    if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + task[i + 1].a) {
                        dp[_i & 1][_j][_k] = dp[i & 1][j][k] + task[i + 1].a;
                        if (state_set.find(state) == state_set.end()) {
                            que.push(DpState(_i, _j, _k));
                            state_set.insert(state);
                        }
                    }
                }

                if (task[i + 1].b <= k) {
                    int _i = i + 1, _j = j, _k = k - task[i + 1].b;
                    int state = (_i << 25) | (_j << 23) | _k;
                    if (dp[_i & 1][_j][_k] > dp[i & 1][j][k]) {
                        dp[_i & 1][_j][_k] = dp[i & 1][j][k];
                        if (state_set.find(state) == state_set.end()) {
                            que.push(DpState(_i, _j, _k));
                            state_set.insert(state);
                        }
                    }
                } else {
                    int _i = i + 1, _j = j ^ 1, _k = task[i + 1].b - k;
                    int state = (_i << 25) | (_j << 23) | _k;
                    if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + _k) {
                        dp[_i & 1][_j][_k] = dp[i & 1][j][k] + _k;
                        if (state_set.find(state) == state_set.end()) {
                            que.push(DpState(_i, _j, _k));
                            state_set.insert(state);
                        }
                    }
                }
            } else {
                // use b
                {
                    int _i = i + 1, _j = j, _k = k + task[i + 1].b;
                    int state = (_i << 25) | (_j << 23) | _k;
                    if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + task[i + 1].b) {
                        dp[_i & 1][_j][_k] = dp[i & 1][j][k] + task[i + 1].b;
                        if (state_set.find(state) == state_set.end()) {
                            que.push(DpState(_i, _j, _k));
                            state_set.insert(state);
                        }
                    }
                }

                if (task[i + 1].a <= k) {
                    int _i = i + 1, _j = j, _k = k - task[i + 1].a;
                    int state = (_i << 25) | (_j << 23) | _k;
                    if (dp[_i & 1][_j][_k] > dp[i & 1][j][k]) {
                        dp[_i & 1][_j][_k] = dp[i & 1][j][k];
                        if (state_set.find(state) == state_set.end()) {
                            que.push(DpState(_i, _j, _k));
                            state_set.insert(state);
                        }
                    }
                } else {
                    int _i = i + 1, _j = j ^ 1, _k = task[i + 1].a - k;
                    int state = (_i << 25) | (_j << 23) | _k;
                    if (dp[_i & 1][_j][_k] > dp[i & 1][j][k] + _k) {
                        dp[_i & 1][_j][_k] = dp[i & 1][j][k] + _k;
                        if (state_set.find(state) == state_set.end()) {
                            que.push(DpState(_i, _j, _k));
                            state_set.insert(state);
                        }
                    }
                }
            }
            dp[i & 1][j][k] = MAX_VAL;
        }

        cout << ans << endl;
    }
    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:31:5: error: ‘memset’ was not declared in this scope
   31 |     memset(dp, MAX_VAL, sizeof(dp));
      |     ^~~~~~
answer.code:7:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    6 | #include <algorithm>
  +++ |+#include <cstring>
    7 | using namespace std;
answer.code:35:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |             scanf("%d%d", &task[i].a, &task[i].b);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~