QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465054#8831. Chemistry Classucup-team2172#WA 50ms12168kbC++231.1kb2024-07-06 17:07:372024-07-06 17:07:37

Judging History

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

  • [2024-07-06 17:07:37]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:12168kb
  • [2024-07-06 17:07:37]
  • 提交

answer

#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
	int ch = 0, f = 0; x = 0;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	if(f) x = -x;
}
const int N = 500005;
int dp[N], s[N], q[N], n;
ll a[N], A, B;
inline void solve(){
	read(n), read(A), read(B);
	for(int i = 1; i <= 2 * n; i++) read(a[i]);
	sort(a + 1, a + 2 * n + 1);
	int h = 1, t = 0;
	for(int i = 1; i <= n - 1; i++)
		s[i] = s[i-1] + (a[2*i+1] - a[2*i] <= B);
	for(int i = 1; i <= n; i++){
		dp[i] = -inf;
		if(a[2*i] - a[2*i-1] <= A)
			dp[i] = dp[i-1] + (a[2*i] - a[2*i-1] <= B);
		while(h <= t && a[2*q[h]+1] < A - a[2*i]) h++;
		if(h <= t) dp[i] = max(dp[i], dp[q[h]] - s[q[h]] + s[i-1]);
		if(i == n) break;
		while(h <= t && dp[q[t]] - s[q[t]] <= dp[i] - s[i]) t--;
		q[t++] = i;
		
	}
	if(dp[n] < 0) puts("-1"); else printf("%d\n", dp[n]);
}
int main(){
	int T; read(T);
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7908kb

input:

4
1 2 1
42 69
2 3 1
1 2 3 4
2 5 1
6 1 3 4
5 19 1
1 7 8 9 10 11 12 13 14 20

output:

-1
2
1
4

result:

ok 4 number(s): "-1 2 1 4"

Test #2:

score: 0
Accepted
time: 50ms
memory: 11888kb

input:

1
199996 67013419502794 1
403716252634677166 895717933735068492 410002430455111886 844431179242134559 322988383133810700 133475121268220299 481706326769800263 606871141911985391 195911124687409946 959578180866483093 930547702157856949 877914383714875160 994158366044742636 890855755285236186 69498488...

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 42ms
memory: 11364kb

input:

1
199998 38987266278826 1
974183459404323858 517476981059568123 730207399881008603 532509909948600146 89227878552241675 16653300445469756 791674368913652595 92177901403222015 980536748304824579 581564387828767376 471919726893404451 759601909683722004 632340812998214017 818440789777778368 18845836031...

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 50ms
memory: 11192kb

input:

1
199996 54170919220045 1
968843690955781467 596307347951820347 406785475849275444 383666938223357986 725160735782817082 132577412512120631 891899794864087098 779434145671998619 932681297277907326 208765550447928461 385078857912267975 669360937040314510 917331948890514855 505938744714587815 47145437...

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: -100
Wrong Answer
time: 46ms
memory: 12168kb

input:

1
199998 35667463938291 8255384928693
770468016026697053 519790816750772730 110085058423772871 85144239858008037 782003096084947976 938498644167289660 693768718229582367 242186248813489674 155335549252315364 428982852761422230 890445026369869037 86401573937739054 9122788624365829 63351367715811463 1...

output:

192729

result:

wrong answer 1st numbers differ - expected: '193326', found: '192729'