QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114049#2103. TermityyanranWA 2ms7756kbC++141.1kb2023-06-20 19:15:532023-06-20 19:15:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-20 19:15:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7756kb
  • [2023-06-20 19:15:53]
  • 提交

answer

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

int read() {
    int x = 0; char ch = getchar();
    while (ch < '0') ch = getchar();
    while (ch >= '0') x = x * 10 + ch - 48, ch = getchar();
    return x;
}

const int N = 1e6 + 3;
const long long inf = 1e17;
int n, m, pos, top, cnt, a[N];
long long ans, sum, q[N], b[N];

void in(long long x) {
	q[++top] = x;
	while (top > 2 && q[top - 1] == max({q[top], q[top - 1], q[top - 1]})) {
		top -= 2;
		q[top] += q[top + 2] - q[top + 1];
	}
}
void out() {
	while (top) b[++cnt] = q[top--];
}

int main() {
    n = read();
    for (int i = 1; i <= n; i++) {
        a[i] = read();
        if (a[i]) {
            sum += a[i], m++;
            if (pos) in(a[i]);
            continue;
        }
		out();
		if (!pos) pos = i;
    }
    in(-inf);// 塞个 -inf 把开头接结尾连成环
    for (int i = 1; i < pos; i++) in(a[i]);
	out();

    sort(b + 1, b + 1 + cnt);
    for (int i = cnt; i; i--) {
		ans += cnt - i & 1 ? -b[i] : b[i];
	}
    ans += m & 1 ? -inf : inf;
	printf("%lld %lld\n", sum + ans >> 1, sum - ans >> 1);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
0

output:

0 0

result:

ok single line: '0 0'

Test #2:

score: 0
Accepted
time: 2ms
memory: 7716kb

input:

2
0 17

output:

17 0

result:

ok single line: '17 0'

Test #3:

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

input:

3
0 13 0

output:

13 0

result:

ok single line: '13 0'

Test #4:

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

input:

8
1 2 0 3 7 4 0 9

output:

17 9

result:

ok single line: '17 9'

Test #5:

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

input:

10
0 0 0 1 0 0 0 5 0 0

output:

5 1

result:

ok single line: '5 1'

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 7592kb

input:

24
55 33 93 169 237 0 219 125 39 13 96 166 200 278 0 99 2 18 110 0 58 57 0 42

output:

1121 988

result:

wrong answer 1st lines differ - expected: '1125 984', found: '1121 988'