QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#690861#5590. Exponent Exchangeohiostatescarlet#WA 0ms3860kbC++172.3kb2024-10-31 06:26:002024-10-31 06:26:02

Judging History

This is the latest submission verdict.

  • [2024-10-31 06:26:02]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3860kb
  • [2024-10-31 06:26:00]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int b, p;
    cin >> b >> p;
    vector<int> nums = vector<int>(p);
    for (int i = p-1; i >= 0; i--) {
        int v;
        cin >> v;
        nums[i] = v;
    }
    int res = INT_MAX;
    for (int z = 0; z < 2; z++) {
        vector<pair<int,int>> curr(1, {INT_MAX, 0});
        for (int i = 0; i < p; i++) {
            vector<pair<int,int>> nex((i+1)*b+1, {INT_MAX, INT_MAX});
            int v = nums[i];
            for (int j = 0; j <= i*b; j++) {
                // We have v+1, they have b-v-1
                int prevRec = curr[j].first;
                if (prevRec != INT_MAX) {
                    if (prevRec+v+1 <= j) {
                        nex[j].second = min(nex[j].second, prevRec+v+1);
                    }
                    nex[j+(b-v-1)].first = min(nex[j+(b-v-1)].first, prevRec);
                }

                // We have v, they have b-v
                int prevGiv = curr[j].second;
                if (prevGiv != INT_MAX) {
                    if (prevGiv+v <= j) {
                        nex[j].second = min(nex[j].second, prevGiv+v);
                    }
                    nex[j+(b-v)].first = min(nex[j+(b-v)].first, prevGiv);
                }
            }
            swap(curr, nex);
            // cout << z << " " << i+1 << "!\n";
            // for (int j = 0; j <= (i+1)*b; j++) {
            //     if (curr[j].first != INT_MAX || curr[j].second != INT_MAX) {
            //         cout << j << ": " << curr[j].first << " " << curr[j].second << "\n";
            //     }
            // }
        }
        for (int i = 0; i <= b * p; i++) {
            if (curr[i].first != INT_MAX || curr[i].second != INT_MAX) {
                res = min(res, i);
                break;
            }
        }
        if (z == 0) {
            for (int i = 0; i < p; i++)
            {
                nums[i] = b - nums[i] - 1;
            }
            nums[0]++;
        }
    }
    cout << res << '\n';
}

/*

50 5
45 45 45 45 45


*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

10 5
4 2 7 8 6

output:

7

result:

ok single line: '7'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3860kb

input:

2 100
1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1

output:

20

result:

wrong answer 1st lines differ - expected: '19', found: '20'