QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#55508#2103. TermityExplodingKonjacRE 77ms16580kbC++174.2kb2022-10-14 11:03:002022-10-14 11:03:03

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-14 11:03:03]
  • 评测
  • 测评结果:RE
  • 用时:77ms
  • 内存:16580kb
  • [2022-10-14 11:03:00]
  • 提交

answer

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

namespace FastIO
{
	class FastIOBase
	{
	protected:
#ifdef OPENIOBUF
		static const int BUFSIZE=1<<22;
		char buf[BUFSIZE+1];
		int buf_p=0;
#endif
		FILE *target;
	public:
#ifdef OPENIOBUF
		virtual void flush()=0;
#endif
		FastIOBase(FILE *f): target(f){}
		~FastIOBase()=default;
	};

	class FastOutput: public FastIOBase
	{
#ifdef OPENIOBUF
	public:
		inline void flush()
			{ fwrite(buf,1,buf_p,target),buf_p=0; }
#endif
	protected:
		inline void __putc(char x)
		{
#ifdef OPENIOBUF
			if(buf[buf_p++]=x,buf_p==BUFSIZE)flush();
#else
			putc(x,target);
#endif
		}
		template<typename T>
		inline void __write(T x)
		{
			static char stk[64],*top;top=stk;
			if(x<0) return __putc('-'),__write(-x);
			do *(top++)=x%10,x/=10; while(x);
			for(;top!=stk;__putc(*(--top)+'0'));
		}
	public:
		FastOutput(FILE *f=stdout): FastIOBase(f){}
#ifdef OPENIOBUF
		~FastOutput(){ flush(); }
#endif
		template<typename ...T>
		inline void writesp(const T &...x)
			{ initializer_list<int>{(this->operator<<(x),__putc(' '),0)...}; }
		template<typename ...T>
		inline void writeln(const T &...x)
			{ initializer_list<int>{(this->operator<<(x),__putc('\n'),0)...}; }
		inline FastOutput &operator <<(char x)
			{ return __putc(x),*this; }
		inline FastOutput &operator <<(const char *s)
			{ for(;*s;__putc(*(s++)));return *this; }
		inline FastOutput &operator <<(const string &s)
			{ return (*this)<<s.c_str(); }
		template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
		inline FastOutput &operator <<(const T &x)
			{ return __write(x),*this; }
	}qout;

	class FastInput: public FastIOBase
	{
#ifdef OPENIOBUF
	public:
		inline void flush()
			{ buf[fread(buf,1,BUFSIZE,target)]='\0',buf_p=0; }
#endif
	protected:
		inline char __getc()
		{
#ifdef OPENIOBUF
			if(buf_p==BUFSIZE) flush();
			return buf[buf_p++];
#else
			return getc(target);
#endif
		}
	public:
#ifdef OPENIOBUF
		FastInput(FILE *f=stdin): FastIOBase(f){ buf_p=BUFSIZE; }
#else
		FastInput(FILE *f=stdin): FastIOBase(f){}
#endif
		inline char getchar() { return __getc(); }
		template<typename ...T>
		inline void read(T &...x)
			{ initializer_list<int>{(this->operator>>(x),0)...}; }
		inline FastInput &operator >>(char &x)
			{ while(isspace(x=__getc()));return *this; }
		template<typename T,typename=typename enable_if<is_integral<T>::value>::type>
		inline FastInput &operator >>(T &x)
		{
			static char ch,sym;x=sym=0;
			while(isspace(ch=__getc()));
			if(ch=='-') sym=1,ch=__getc();
			for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=__getc());
			return sym?x=-x:x,*this;
		}
		inline FastInput &operator >>(char *s)
		{
			while(isspace(*s=__getc()));
			for(;!isspace(*s) && *s && ~*s;*(++s)=__getc());
			return *s='\0',*this;
		}
		inline FastInput &operator >>(string &s)
		{
			char str_buf[(1<<8)+1],*p=str_buf;
			char *const buf_end=str_buf+(1<<8);
			while(isspace(*p=__getc()));
			for(s.clear(),p++;;p=str_buf)
			{
				for(;p!=buf_end && !isspace(*p=__getc()) && *p && ~*p;p++);
				*p='\0',s.append(str_buf);
				if(p!=buf_end) break;
			}
			return *this;
		}
	}qin;
}
using namespace FastIO;

typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
const LL INF=1e18;

#ifndef DADALZY
#define FILEIO(file) freopen(file".in","r",stdin),freopen(file".out","w",stdout)
#else
#define FILEIO(file)
#endif

LL n,sum,a[1000005];
vector<LL> vec;
void process(int l,int r)
{
	static LL top,st[1000005];
	for(int i=l;i<=r;i++)
	{
		LL x=a[i];
		while(top>1 && st[top]>=x && st[top]>=st[top-1])
			x+=st[top-1]-st[top],top-=2;
		st[++top]=x;
	}
	while(top) vec.push_back(st[top--]);
}
int main()
{
	qin>>n;
	for(int i=1;i<=n;i++) qin>>a[i],sum+=a[i];
	a[0]=-INF,sum-=INF;
	for(int i=0,j=0;i<=n;i++,j++)
	{
		if(!a[i]) continue;
		while(a[j]) j++;
		if(i) process(i,j-1);
		else for(int k=0;k<j;k++) a[++n]=a[k];
		i=--j;
	}
	sort(vec.begin(),vec.end(),greater<LL>());
	LL tmp=0,fl=0;
	for(auto &i: vec) (fl?tmp-=i:tmp+=i),fl^=1;
	LL ans1=(sum+tmp)/2,ans2=(sum-tmp)/2;
	if(ans1<0) ans1+=INF;
	if(ans2<0) ans2+=INF;
	qout.writesp(ans1,ans2);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5736kb

input:

1
0

output:

0 0 

result:

ok single line: '0 0 '

Test #2:

score: 0
Accepted
time: 3ms
memory: 5740kb

input:

2
0 17

output:

17 0 

result:

ok single line: '17 0 '

Test #3:

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

input:

3
0 13 0

output:

13 0 

result:

ok single line: '13 0 '

Test #4:

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

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

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

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

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

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: 2ms
memory: 5780kb

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

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: 2ms
memory: 5608kb

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: 2ms
memory: 5616kb

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: 2ms
memory: 5620kb

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: 1ms
memory: 5616kb

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: 1ms
memory: 5712kb

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: 2ms
memory: 5648kb

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: 2ms
memory: 5612kb

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: 2ms
memory: 5636kb

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: 1ms
memory: 5752kb

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

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: 2ms
memory: 5512kb

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: 2ms
memory: 5640kb

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: 0ms
memory: 5736kb

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: 2ms
memory: 5596kb

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: 77ms
memory: 16580kb

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: -100
Runtime Error

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:


result: