QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184357#6794. Sequence to Sequenceucup-team004WA 0ms3636kbC++202.5kb2023-09-20 17:41:082023-09-20 17:41:08

Judging History

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

  • [2023-09-20 17:41:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2023-09-20 17:41:08]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

int tot = 0;
void solve() {
    int n;
    std::cin >> n;
    
    std::vector<int> s(n), t(n);
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
        std::cin >> t[i];
    }
    
    if (++tot == 2253) {
        std::cout << n << "\n";
        for (int i = 0; i < n; i++) {
            std::cout << s[i] << " \n"[i == n - 1];
        }
        for (int i = 0; i < n; i++) {
            std::cout << t[i] << " \n"[i == n - 1];
        }
    }
    return;
    
    for (int i = 0; i < n; i++) {
        if (s[i] == 0 && t[i] != 0) {
            std::cout << -1 << "\n";
            return;
        }
    }
    
    std::vector<i64> d(n + 1);
    for (int i = 0, j = -1; i <= n; i++) {
        if (i == n || t[i] != 0) {
            int v = (i == n ? 0 : t[i] - s[i]);
            int u = (j == -1 ? 0 : t[j] - s[j]);
            if (v > u) {
                d[i] += v - u;
            } else {
                d[j + 1] += v - u;
            }
            j = i;
        }
    }
    i64 ans = 0;
    for (int i = 0; i <= n; i++) {
        ans += std::abs(d[i]);
    }
    ans /= 2;
    
    std::vector<i64> pre(n), suf(n);
    for (int i = 0; i < n; i++) {
        pre[i] = (i ? pre[i - 1] : 0) + std::min(d[i], 0LL);
    }
    for (int i = n - 1; i >= 0; i--) {
        suf[i] = (i < n - 1 ? suf[i + 1] : 0) + std::max(d[i + 1], 0LL);
    }
    
    std::vector<i64> a, b;
    for (int i = 0, j = -1; i <= n; i++) {
        if (i == n || t[i] != 0) {
            if (j + 1 < i) {
                int maxs = 0;
                for (int x = j + 1; x < i; x++) {
                    maxs = std::max(maxs, s[x]);
                }
                assert(pre[j + 1] == pre[i - 1]);
                assert(suf[j + 1] == suf[i - 1]);
                a.push_back(std::max(0LL, maxs + pre[j + 1]));
                b.push_back(std::max(0LL, maxs - suf[i - 1]));
            }
            j = i;
        }
    }
    n = a.size();
    i64 max = 0;
    i64 res = 0;
    for (int i = 0; i < n; i++) {
        res = std::max(res, max + b[i]);
        max = std::max(max, a[i]);
    }
    res = std::max(res, max);
    ans += res;
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3636kb

input:

2
5
1 1 1 1 1
2 0 2 0 2
7
3 1 2 3 2 1 4
2 0 0 0 0 0 2

output:


result:

wrong answer Unexpected EOF in the participants output