QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395373#7067. The Great Wallsuibian_xiaozhao#WA 1ms3780kbC++231.5kb2024-04-21 13:53:022024-04-21 13:53:02

Judging History

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

  • [2024-04-21 13:53:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3780kb
  • [2024-04-21 13:53:02]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define debug(x)  cerr <<#x<<" "<<x<<endl;
using ll = long long;
#define int ll
struct node {
    int ma, mi, va;
};
const int inf = -1e18;

node merry(node &a, node &b) {
    int mins = min(a.mi, b.mi);
    int maxs = max(a.ma, b.ma);
    node c;
    c.ma = maxs;
    c.mi = mins;
    c.va = maxs - mins;
    return c;

};

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    vector<node> v(n + 1);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        v[i].mi = v[i].ma = x;
        v[i].va = 0;
    }
    stack<int> ans;
    ans.emplace(0);
    for (int i = 1; i < n; i++) {
        int len = 0;
        int maxs = -inf;
        for (int j = 1; j <= n - i; j++) {
            node c = merry(v[j], v[j + 1]);
            if (maxs > v[j].va + v[j + 1].va - c.va) {
                maxs = v[j].va + v[j + 1].va - c.va;
                len = j;
            }
        }

        vector<node> mir(n - i + 1);
        for (int j = 1; j < len; j++) {
            mir[j] = v[j];
        }
        mir[len] = merry(v[len], v[len + 1]);
        ans.emplace(ans.top() - v[len].va - v[len + 1].va + mir[len].va);
//        debug(ans.top());
        for (int j = len + 2; j <= n - i + 1; j++) {
            mir[j - 1] = v[j];
        }
        v = mir;
    }
    while (!ans.empty()) {
        cout << ans.top() << endl;
        ans.pop();
    }
}

详细

Test #1:

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

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: 3560kb

input:

5
1 2 1 2 1

output:

1
2
2
1
0

result:

ok 5 lines

Test #3:

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

input:

6
1 1 4 5 1 4

output:

4
7
7
7
4
0

result:

ok 6 lines

Test #4:

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

input:

6
1 9 1 9 8 1

output:

8
16
23
16
8
0

result:

ok 6 lines

Test #5:

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

input:

12
1 1 4 5 1 4 1 9 1 9 8 1

output:

8
16
23
27
30
30
30
27
23
16
8
0

result:

ok 12 lines

Test #6:

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

input:

1
79932

output:

0

result:

ok single line: '0'

Test #7:

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

input:

500
2 4 2 9 3 1 9 1 2 9 9 9 2 3 8 6 6 5 6 4 9 9 6 4 4 3 1 3 4 6 9 7 1 8 3 10 1 1 1 1 2 2 8 4 4 1 9 1 3 7 5 10 1 3 2 1 3 4 8 4 2 2 2 3 10 8 8 8 6 1 3 5 10 10 6 7 9 7 3 2 5 5 4 10 2 2 8 6 10 8 8 10 4 1 9 8 1 7 10 10 1 1 4 3 8 7 10 3 3 7 3 3 4 1 1 4 1 7 8 2 8 9 6 4 6 6 7 1 3 9 4 4 4 10 8 5 6 7 8 6 6 5 ...

output:

9
18
27
36
45
54
63
72
81
90
99
108
117
126
135
144
153
162
171
180
189
198
207
216
225
234
243
252
261
270
279
288
297
305
313
321
329
337
345
353
361
369
377
385
393
401
409
417
425
433
441
449
457
465
473
481
489
496
503
510
517
524
531
538
545
552
559
566
573
580
587
594
601
607
613
619
625
631
...

result:

wrong answer 34th lines differ - expected: '306', found: '305'