QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133523#4931. Comic BingeVengeful_Spirit#WA 1ms3568kbC++201.4kb2023-08-02 10:39:102023-08-02 10:39:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 10:39:13]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3568kb
  • [2023-08-02 10:39:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

void Min(int &x, int y) {
    x = min(x, y);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    int sum = 0, tot = 0;
    for(int &x : a) {
        cin >> x;
        tot += x;
    }
    for(int &x : b) {
        cin >> x;
        sum += x;
    }
    vector<int> f(sum + 1, 1e9), q(sum + 1, 1e9);
    f[b[0]] = 0;
    for(int i = 1; i < n; ++i) {
        // cerr << i << "\n";
        vector<int> g(sum + 1, 1e9);
        for(int j = 0; j <= sum; ++j) {
            if(f[j] != 1e9) {
                // cerr << j << "jj\n";
                int pos = f[j] + b[i] - a[i - 1];
                // cerr << j << " , pos = " << pos << "\n";
                if(pos > 0) Min(g[j + pos], 0);
                else Min(g[j], pos);
            } 
            if(q[j] != 1e9 && i > 1) {
                // cerr << i << "qq\n";
                int pos = q[j] + b[i] - a[i - 1] - a[i - 2];
                if(pos > 0) Min(g[j + pos], 0);
                else Min(g[j], pos);
            }
        }
        // for(int j = 0; j <= sum; ++j) if(g[j] != 1e9) {
        //     cerr << j << " " << g[j] << "\n";
        // }
        q = f, f = g;
    }
    int ans = 1e9;
    for(int i = 0; i < sum; ++i) {
        ans = min(ans, i + max(0, f[i]));
    }
    cout << ans + tot << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6
3 1 1 1 1 2
1 5 3 3 7 4

output:

13

result:

ok single line: '13'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

2
2 1
1 1

output:

4

result:

ok single line: '4'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3568kb

input:

1
1
1

output:

1000000001

result:

wrong answer 1st lines differ - expected: '2', found: '1000000001'