QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#338700 | #2103. Termity | hos_lyric | AC ✓ | 98ms | 19196kb | C++14 | 3.4kb | 2024-02-26 08:46:50 | 2024-02-26 08:46:51 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")
/*
problem
2-player game
move: choose an element adjacent to 0, get score, change it to 0
*/
struct Stack {
vector<Int> as, bs;
void push(Int a) {
for (; as.size() && as.back() >= a; ) {
const Int a1 = as.back(); as.pop_back();
if (!as.size()) {
bs.push_back(a - a1);
return;
}
const Int a2 = as.back(); as.pop_back();
a = a - a1 + a2;
}
as.push_back(a);
}
void get(vector<Int> &goods, vector<Int> &bads) {
// cerr<<"[Stack::get] "<<as<<" "<<bs<<endl;
goods.insert(goods.end(), as.begin(), as.end());
bads.insert(bads.end(), bs.begin(), bs.end());
}
};
int N;
vector<Int> A;
int main() {
for (; ~scanf("%d", &N); ) {
A.resize(N);
for (int i = 0; i < N; ++i) {
scanf("%lld", &A[i]);
}
vector<Int> goods, bads;
vector<int> cuts;
for (int i = 0; i < N; ++i) if (!A[i]) {
cuts.push_back(i);
}
const int cutsLen = cuts.size();
assert(cutsLen >= 1);
Stack f, g;
for (int i = 0; i < cuts[0]; ++i) f.push(A[i]);
f.get(goods, bads);
for (int i = N; --i > cuts[cutsLen - 1]; ) g.push(A[i]);
g.get(goods, bads);
for (int j = 1; j < cutsLen; ++j) {
vector<Int> as;
for (int i = cuts[j - 1] + 1; i < cuts[j]; ++i) {
Int a = A[i];
for (; as.size() >= 2 && as[as.size() - 2] <= as.back() && as.back() >= a; ) {
const Int a1 = as.back(); as.pop_back();
const Int a2 = as.back(); as.pop_back();
a = a - a1 + a2;
}
as.push_back(a);
}
// cerr<<"deque "<<as<<endl;
goods.insert(goods.end(), as.begin(), as.end());
}
sort(goods.begin(), goods.end(), greater<Int>{});
// cerr<<"goods = "<<goods<<endl;
// cerr<<"bads = "<<bads<<endl;
Int ans = 0;
int sig = +1;
for (const Int good : goods) {
ans += sig * good;
sig = -sig;
}
for (const Int bad : bads) {
ans += sig * bad;
}
Int sumA = 0;
for (int i = 0; i < N; ++i) sumA += A[i];
printf("%lld %lld\n", (sumA + ans) / 2, (sumA - ans) / 2);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
input:
1 0
output:
0 0
result:
ok single line: '0 0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
2 0 17
output:
17 0
result:
ok single line: '17 0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
3 0 13 0
output:
13 0
result:
ok single line: '13 0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3748kb
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: 0ms
memory: 3768kb
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: 0ms
memory: 4060kb
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: 0ms
memory: 4040kb
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: 3828kb
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: 0ms
memory: 3848kb
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: 0ms
memory: 4068kb
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: 0
Accepted
time: 0ms
memory: 3752kb
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:
17181 17930
result:
ok single line: '17181 17930'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3772kb
input:
136 991 304 34 364 498 254 893 687 126 153 997 976 189 158 730 437 461 415 922 461 305 29 28 51 749 557 903 795 698 700 44 40 3 429 404 501 682 648 539 160 152 536 135 340 693 216 128 505 630 50 965 286 430 344 336 178 901 239 972 950 290 368 989 293 0 796 744 145 830 391 683 341 542 570 827 233 262...
output:
30192 32764
result:
ok single line: '30192 32764'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
141 1872 1860 1773 1755 1676 1620 1575 1568 1532 1490 1414 1330 1240 1200 1116 1050 1024 929 839 771 758 685 626 530 431 350 251 188 128 34 73 132 141 177 187 229 316 322 323 336 408 429 484 503 602 623 627 666 677 717 784 789 817 844 894 978 1036 1056 1080 1102 1171 1267 1348 1378 1462 1554 1626 16...
output:
66031 66354
result:
ok single line: '66031 66354'
Test #14:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
200 814 858 495 182 82 604 721 434 983 182 488 416 297 826 0 723 893 552 298 33 135 0 507 416 58 709 596 1000 963 298 484 0 155 978 310 588 0 383 22 0 564 861 683 212 0 87 286 931 991 0 315 477 117 821 893 526 529 840 526 491 137 361 619 644 0 0 583 622 311 956 889 226 816 0 438 854 9 0 784 351 658 ...
output:
43498 42858
result:
ok single line: '43498 42858'
Test #15:
score: 0
Accepted
time: 0ms
memory: 4068kb
input:
200 912 128 951 237 561 819 106 564 50 245 712 806 935 292 376 956 615 590 769 994 919 806 883 823 983 718 31 94 575 127 594 487 254 544 75 815 714 180 378 763 776 89 920 711 733 295 18 347 236 138 692 154 944 574 0 926 292 711 19 218 837 964 56 91 859 131 905 572 662 634 686 790 74 605 852 806 251 ...
output:
49121 45904
result:
ok single line: '49121 45904'
Test #16:
score: 0
Accepted
time: 0ms
memory: 4036kb
input:
100 0 530498339 873524567 37487771 541027285 232056857 745790418 251300607 959372261 25125850 137100238 126107206 159473060 376035218 282648519 478034946 471990784 353436874 983228459 584710874 993967638 941804290 826620484 45826608 37770479 930772758 647149315 716334472 152645730 470591101 25533460...
output:
24979181322 21081522362
result:
ok single line: '24979181322 21081522362'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
100 186452552 244316438 971899229 476153276 213975408 139901475 626276122 653468859 130794396 239036030 884661238 605908236 350573794 76065819 605894429 789366144 987231012 875335929 784639530 103318777 597322405 939964444 112255764 432114614 67854539 352118607 782436841 909002905 165344819 39523512...
output:
24240077298 21243698472
result:
ok single line: '24240077298 21243698472'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
474 4427 4367 4269 4210 4181 4151 4146 4098 4013 3920 3840 3766 3740 3687 3646 3628 3532 3435 3402 3377 3315 3258 3185 3113 3026 2949 2866 2850 2832 2825 2751 2749 2718 2650 2648 2619 2527 2515 2448 2437 2371 2296 2215 2159 2155 2112 2079 2060 1977 1901 1850 1812 1743 1699 1610 1591 1532 1508 1466 1...
output:
507770 511012
result:
ok single line: '507770 511012'
Test #19:
score: 0
Accepted
time: 0ms
memory: 4076kb
input:
1000 630 764 101 0 398 417 776 983 545 541 321 827 519 566 0 500 135 547 909 854 63 304 687 0 433 535 808 0 835 0 0 0 985 0 325 383 466 0 717 362 344 38 0 0 603 982 0 89 880 621 942 0 925 629 136 0 163 0 871 0 164 0 0 501 0 488 235 333 291 951 694 634 340 881 495 294 214 855 0 445 476 324 739 752 95...
output:
206486 205459
result:
ok single line: '206486 205459'
Test #20:
score: 0
Accepted
time: 0ms
memory: 4080kb
input:
1000 0 79 197 274 190 853 834 594 775 997 788 98 645 538 781 272 895 235 580 33 415 678 629 124 24 181 525 505 590 488 577 885 918 125 158 108 977 343 53 104 691 841 201 336 378 981 607 272 567 539 657 981 568 637 457 591 169 981 95 759 820 23 995 89 148 504 196 476 198 601 579 889 793 131 224 170 4...
output:
245705 242601
result:
ok single line: '245705 242601'
Test #21:
score: 0
Accepted
time: 0ms
memory: 4072kb
input:
1000 164 818 235 340 935 353 550 894 819 443 505 6 905 914 693 303 945 188 5 362 257 102 527 749 328 51 55 940 797 810 446 312 627 681 3 913 33 553 158 204 347 662 561 251 928 253 554 872 441 558 585 49 11 112 149 338 514 555 278 662 364 75 325 343 755 327 255 140 879 765 343 226 778 903 828 705 155...
output:
247371 242089
result:
ok single line: '247371 242089'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
1000 809908776 832077980 92295432 315859325 770016229 696739072 228756838 48426762 449631210 972740482 240738544 184177382 114060443 379931498 278893609 832106134 865543723 514127926 23421466 143288219 887372904 984078613 693149221 84538076 835707305 954882015 261817690 114928238 131871223 98247531 ...
output:
222855153147 221652607448
result:
ok single line: '222855153147 221652607448'
Test #23:
score: 0
Accepted
time: 1ms
memory: 3784kb
input:
2000 675365724 0 0 247906198 545042418 0 626717775 112718117 234815956 696779466 30245416 377970869 171029950 552604754 354321180 0 373026857 0 644210802 242660716 0 0 189059477 0 0 497905612 0 0 233983203 0 833639404 761865278 0 650076586 9771476 685622012 0 0 798340128 0 0 0 0 0 0 0 130324324 6067...
output:
281582543785 281784474195
result:
ok single line: '281582543785 281784474195'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
2000 0 735030707 239079909 783122046 0 0 0 596488876 0 44805129 581296003 682679471 457384565 0 707321101 74961687 0 0 627423305 349672636 821281469 0 130812281 126497923 0 0 0 646927302 0 0 555501256 0 0 0 0 0 0 291248360 0 0 188569840 0 367651185 0 0 927488637 0 117165684 643465975 0 319354672 317...
output:
281704826998 280699038290
result:
ok single line: '281704826998 280699038290'
Test #25:
score: 0
Accepted
time: 98ms
memory: 18664kb
input:
1000000 201586286 0 416430488 0 978137396 0 789522972 0 236793095 0 710795253 0 262917289 0 556681937 0 860227851 0 556210053 0 514135834 0 360739836 0 594048446 0 199332799 0 747011474 0 636503898 0 774599077 0 899255998 0 555366032 0 812445254 0 144600126 0 929101428 0 989865586 0 109775039 0 4268...
output:
117639050447030 117638549281772
result:
ok single line: '117639050447030 117638549281772'
Test #26:
score: 0
Accepted
time: 47ms
memory: 19196kb
input:
1000000 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 100000...
output:
500000000000000 499999
result:
ok single line: '500000000000000 499999'
Test #27:
score: 0
Accepted
time: 77ms
memory: 11788kb
input:
1000000 713115457 408187027 969481833 589156845 755100257 411636174 226349521 10719046 638450035 902574022 661331871 830343004 500885925 152194128 964166887 180108577 595807806 775037932 5292949 910291148 573143120 546733139 664293647 937673570 170669250 907548006 47400411 328063029 826984298 929042...
output:
233013683820657 233022939318001
result:
ok single line: '233013683820657 233022939318001'
Test #28:
score: 0
Accepted
time: 73ms
memory: 11372kb
input:
1000000 811015121 382728104 20091485 989199233 9396401 17362763 81608748 94033484 321901901 319796228 139108590 707552323 212932029 464540077 344105643 708090211 820312757 567508612 742828516 330786018 834767819 616301450 150950231 111996022 690173662 262941572 638711487 897678935 410431249 37146567...
output:
235173412664470 235197598443273
result:
ok single line: '235173412664470 235197598443273'
Test #29:
score: 0
Accepted
time: 73ms
memory: 11056kb
input:
1000000 248854431 804708287 378708443 171793522 127623522 980595599 796955393 218170327 528950933 394114582 157737036 34575819 647761444 863999145 15491159 181265671 890996999 278164608 372816728 956962045 353785545 820841106 103918487 960034308 25563383 891339990 401068717 37063052 740691798 212666...
output:
235309085530688 235242602763974
result:
ok single line: '235309085530688 235242602763974'