QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#53251 | #2103. Termity | Famiglistmo# | WA | 2ms | 3804kb | C++14 | 2.2kb | 2022-10-04 20:51:20 | 2022-10-04 20:51:22 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
char buf[1 << 23], *p1 = buf, *p2 = buf;
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1 ++ )
int read() {
int s = 0, w = 1; char ch = getchar();
while(!isdigit(ch)) { if(ch == '-') w = -1; ch = getchar(); }
while(isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
return s * w;
}
vector<int> vec, num;
int a[N], stk[N];
int n, top, dif, sum, cnt;
void append(int x) {
if(top <= 1) stk[++ top] = x;
else {
if(stk[top - 1] <= stk[top] && x <= stk[top])
// cout << stk[top - 1] << " " << stk[top] << " " << x << endl,
stk[top - 1] += x - stk[top], -- top;
else stk[++ top] = x;
}
}
void work(int l, int r) {
if(l > r) return ;
// cout << l << " " << r << endl;
assert(!(l == r && a[l] == 0));
top = 0;
if(r == n) for(int i = r; i >= l; -- i) append(a[i]);
else for(int i = l; i <= r; ++ i) append(a[i]);
// for(int i = 1; i <= top; ++ i) cout << stk[i] << " "; puts("");
int s = 0, ptr = 1;
if(l == 1 || r == n) {
while(ptr + 1 <= top && stk[ptr] >= stk[ptr + 1])
s += stk[ptr] - stk[ptr + 1], ptr += 2;
// if(ptr != 1) num.push_back(s); // wrong, must be the last or last but one step.
if(cnt & 1) dif += s;
else dif -= s;
}
for(int i = ptr; i <= top; ++ i)
num.push_back(stk[i]);
}
signed main() {
n = read();
vec.push_back(0);
for(int i = 1; i <= n; ++ i) {
a[i] = read(), sum += a[i], cnt += (bool)a[i];
if(a[i] == 0) vec.push_back(i);
}
vec.push_back(n + 1);
for(int i = 1; i < (int)vec.size(); ++ i)
work(vec[i - 1] + 1, vec[i] - 1);
// for(auto v : num) cout << v << " "; puts("");
sort(num.begin(), num.end(), greater<int>());
for(int i = 0; i < (int)num.size(); ++ i)
if(i & 1) dif -= num[i];
else dif += num[i];
// for(int i = 0; i < (int)num.size(); ++ i)
// if(i & 1) b += num[i];
// else a += num[i];
printf("%lld %lld\n", (sum + dif) / 2, (sum - dif) / 2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3588kb
input:
1 0
output:
0 0
result:
ok single line: '0 0'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3800kb
input:
2 0 17
output:
17 0
result:
ok single line: '17 0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3712kb
input:
3 0 13 0
output:
13 0
result:
ok single line: '13 0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3640kb
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: 2ms
memory: 3760kb
input:
10 0 0 0 1 0 0 0 5 0 0
output:
5 1
result:
ok single line: '5 1'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3716kb
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:
1125 984
result:
ok single line: '1125 984'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3704kb
input:
17 805750847 0 100661314 433925858 0 84353896 0 0 998898815 548233368 610515435 585990365 374344044 760313751 477171088 356426809 945117277
output:
4023568786 3058134081
result:
ok single line: '4023568786 3058134081'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
19 0 294702568 726956430 336465783 861021531 278722863 233665124 145174068 468703136 101513930 801979803 315634023 635723059 369133070 0 59961394 89018457 628175012 656478043
output:
2586842805 4416185489
result:
ok single line: '2586842805 4416185489'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3732kb
input:
21 859484422 914544920 608413785 756898538 734575199 0 149798316 38664371 129566414 184803527 412776092 424268981 0 749241874 137806863 42999171 982906997 0 511702306 84420926 937477085
output:
4059679871 4600669916
result:
ok single line: '4059679871 4600669916'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3680kb
input:
20 804289384 846930887 681692778 714636916 957747794 424238336 719885387 649760493 596516650 189641422 25202363 0 783368691 102520060 44897764 967513927 365180541 540383427 304089173 303455737
output:
6380056138 3641895592
result:
ok single line: '6380056138 3641895592'
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 3764kb
input:
67 690 445 620 441 730 32 118 98 772 482 676 710 928 568 857 0 498 354 587 966 307 684 220 625 529 872 733 830 504 0 20 271 369 709 716 341 150 797 724 619 246 847 452 922 556 380 489 0 765 229 842 351 194 501 35 765 125 915 988 857 744 492 228 366 860 937 433
output:
17283 17828
result:
wrong answer 1st lines differ - expected: '17181 17930', found: '17283 17828'