QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#168339#7067. The Great Wallsupepapupu#WA 1ms4068kbC++171.4kb2023-09-08 10:14:192023-09-08 10:14:20

Judging History

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

  • [2023-09-08 10:14:20]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4068kb
  • [2023-09-08 10:14:19]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e4 + 10, INF = 0x3f3f3f3f, mod = 998244353;

inline int read() {
    int f = 1, k = 0;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        k = k * 10 + c - '0';
        c = getchar();
    }
    return f * k;
}

int n;
int a[N], f[N], dp[N];

int main() {
    // ios::sync_with_stdio(0); cin.tie(0);
    n = read();
    for (int i = 1; i <= n; ++i) a[i] = read();
    vector<int> ans;
    for (int k = 1; k <= n; ++k) {
        // int g = -INF, h = -INF;
        // for (int i = 1; i <= k; ++i) {
        //     g = max(g, dp[i - 1] - a[i]);
        //     h = max(h, dp[i - 1] + a[i]);
        // }
        int g = dp[k - 1] - a[k];
        int h = dp[k - 1] + a[k];
        for (int i = 1; i <= k; ++i) f[i] = 0;
        for (int i = k + 1; i <= n; ++i) {
            f[i] = max(g + a[i], h - a[i]);
            g = max(g, dp[i - 1] - a[i]);
            h = max(h, dp[i - 1] + a[i]);
            // cout << f[i] << " \n"[i == n];
        }
        ans.emplace_back(f[n]);
        printf("%d\n", f[n]);
        swap(f, dp);
    }
    // for (int i: ans) printf("%d\n", i);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2 3 4 5

output:

4
3
2
1
0

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

5
1 2 1 2 1

output:

1
2
2
1
0

result:

ok 5 lines

Test #3:

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

input:

6
1 1 4 5 1 4

output:

3
7
7
4
3
0

result:

wrong answer 1st lines differ - expected: '4', found: '3'