QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614069#8831. Chemistry Classucup-team2432#WA 10ms13616kbC++201.6kb2024-10-05 15:32:052024-10-05 15:32:06

Judging History

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

  • [2024-10-05 15:32:06]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:13616kb
  • [2024-10-05 15:32:05]
  • 提交

answer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(),vec.end()
#define umap __gnu_pbds::gp_hash_table
using ll = long long;
using db = double;
#define Emu Smile
using namespace std;

void chmax(auto &a, auto b) { if (a < b) a = b; }
void chmin(auto &a, auto b) { if (a > b) a = b; }
inline int lbt(int x) { return x & (-x); }

const ll inf = 1e16;

void solve() {
	int n,A,B; cin >> n >> A >> B; n *= 2;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(all(a));
	for (int i = 0; i < n; i += 2) {
		if (a[i+1] - a[i] >	A) {
			cout << -1 << '\n'; return;
		}
	}
	vector<ll> f(n+1), pre(n+2);
	for (int i = 1; i < n; ++i) {
		pre[i+1] = pre[i-1];
		if (a[i] - a[i-1] <= B) {
			pre[i+1] ++;
		}
	}
	vector<int> stack;
	stack.emplace_back(0);
	for (int i = 1, j = 0; i < n; i += 2) {
		while (sz(stack) > j && a[stack[j]] + A < a[i]) {
			j ++;
		}
		int t = stack[j];
		f[i+1] = f[t] + pre[i] - pre[t+1];
		chmax(f[i+1], f[i-1] + (a[i] - a[i-1] <= B));
		while (sz(stack) > j) {
			int b = stack.back();
			if (f[b] - pre[b+1] < f[i+1] - pre[i+2]) stack.pop_back();
			else break;
		}
		stack.emplace_back(i+1);
	}
	cout << f[n] << '\n';
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);

//	init();

	cout << fixed << setprecision(2);

	int OuO = 1;
	cin >> OuO;
	for (int piastic = 0; piastic < OuO; ++piastic) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3504kb

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: -100
Wrong Answer
time: 10ms
memory: 13616kb

input:

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

output:

199996

result:

wrong answer 1st numbers differ - expected: '0', found: '199996'