QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59195#2541. Coins and BoxesHongzy#WA 25ms5336kbC++823b2022-10-28 16:06:322022-10-28 16:06:33

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-28 16:06:33]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:5336kb
  • [2022-10-28 16:06:32]
  • 提交

answer

#include<bits/stdc++.h>
#define M 200005
#define ll long long
using namespace std;
void Rd(int &res) {
	res=0;
	char c;
	int fl=1;
	while(c=getchar(),c<48)if(c=='-')fl=-1;
	do res=(res<<1)+(res<<3)+(c^48);
	while(c=getchar(),c>=48);
	res*=fl;
}
int n;
ll ans;
void Min(ll &x,ll y) {
	if(x>y)x=y;
}
struct node {
	int x,op;
	bool operator<(const node&_)const {
		return x<_.x;
	}
} a[M];
int main() {
	Rd(n);
	for(int i=1; i<=n; i++)Rd(a[i].x),a[i].op=-1;
	for(int i=n+1; i<=n*2; i++)Rd(a[i].x),a[i].op=1;
	n*=2;
	sort(a+1,a+n+1);
	ans=a[n].x;
	ll now=0,tot=0;
	a[n+1]=a[n];
	for(int i=1;i<=n;i++){
		now+=a[i].op;
		if(now<0)tot+=(a[i+1].x-a[i].x)*2;
//		printf("%lld %lld %lld\n",tot,a[n].x,a[i+1].x);
		Min(ans,tot+a[n].x-a[i+1].x);
	}		
	printf("%lld\n",ans+a[n].x);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3636kb

input:

4
1 6 7 12
3 5 10 11

output:

21

result:

ok answer is '21'

Test #2:

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

input:

2
1 2
1 1000000000

output:

1999999998

result:

ok answer is '1999999998'

Test #3:

score: 0
Accepted
time: 15ms
memory: 5196kb

input:

100000
967 3246 9492 10300 15195 16650 26911 54855 83695 112841 125511 137160 153051 155859 177924 187843 214838 219388 247276 249612 250188 253873 257830 261805 281312 297030 298332 325904 333218 339683 374111 387794 396645 403705 426710 436137 463368 481801 501933 509267 511332 515225 515629 51686...

output:

1722240547

result:

ok answer is '1722240547'

Test #4:

score: 0
Accepted
time: 21ms
memory: 5220kb

input:

99999
21462 34020 34146 53248 90164 92224 98994 104980 115343 128362 134989 136436 149380 154685 181264 182990 205001 209721 213620 233438 238959 247963 248072 250838 259705 264873 265121 298034 298867 304937 325609 325758 334451 341321 363426 374659 396164 414311 424279 445253 454970 482336 505116 ...

output:

1469284712

result:

ok answer is '1469284712'

Test #5:

score: 0
Accepted
time: 24ms
memory: 5248kb

input:

99998
662 69065 90516 119024 146215 146391 152295 166603 168318 170511 185082 191597 203549 220156 222019 233462 233502 235131 247440 254351 278648 283202 287150 312840 318686 332272 344963 374235 386478 390405 391828 421104 424282 437621 438490 444582 448853 455370 468914 482565 507931 528031 53129...

output:

1782189953

result:

ok answer is '1782189953'

Test #6:

score: -100
Wrong Answer
time: 25ms
memory: 5336kb

input:

99997
1036 12224 16393 26262 26675 29724 38487 44675 52169 56398 62749 104395 122412 123854 140544 184458 187993 191357 204244 216509 225345 225651 229547 231850 240978 243269 250984 255594 271277 281251 286151 300018 301497 302196 302973 310350 321582 323564 328049 332303 335816 352755 356321 35992...

output:

1999998484

result:

wrong answer expected '1999997448', found '1999998484'