QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208130#6416. Classical Scheduling ProblemduckierWA 160ms5932kbC++143.5kb2023-10-09 06:23:132023-10-09 06:23:14

Judging History

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

  • [2023-10-09 06:23:14]
  • 评测
  • 测评结果:WA
  • 用时:160ms
  • 内存:5932kb
  • [2023-10-09 06:23:13]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

struct node {
	int a;
	int b;
	int idx;
};

const int MAXN = 2e5 + 5;
int q, n, t, tot;
node topics[MAXN], sorted[MAXN];
auto cmp2 = [](int i1, int i2) { 
	if (topics[i1].a == topics[i2].a) {
		return topics[i1].idx < topics[i2].idx;
	}
	return topics[i1].a < topics[i2].a; 
};
set<int, decltype(cmp2)> usedl(cmp2), unusedl(cmp2), usedr(cmp2), unusedr(cmp2);
bool istheone = false;
int tc = 0;

bool cmp(node n1, node n2) {
	if (n1.b == n2.b) {
		return n1.a < n2.a;
	}
	return n1.b < n2.b;
}

bool incm() {
	if (unusedr.empty()) {
		return false;
	}
	int minuu = *(unusedr.begin());
	tot += topics[minuu].a;
	usedr.insert(minuu);
	unusedr.erase(unusedr.begin());
	return true;
}

bool add(int x) {
	unusedl.insert(x);
	int maxu = *usedl.rbegin(), minuu = *unusedl.begin();
	if (topics[maxu].a > topics[minuu].a) {
		//replace with cheaper option
		usedl.insert(minuu);
		unusedl.erase(unusedl.begin());
		usedl.erase(--usedl.end());
		unusedl.insert(maxu);
		tot += topics[minuu].a - topics[maxu].a;
	}
	//process right side
	if (usedr.find(x) != usedr.end()) {
		//if (istheone) return true;
		//is using this one
		usedr.erase(x);
		if (unusedr.empty()) {
			return false;
		}
		int minuu = *unusedr.begin();
		usedr.insert(minuu);
		unusedr.erase(unusedr.begin());
	}
	else {
		unusedr.erase(x);
	}
	return true;
}

bool test(int k) {
	int s = max(k, sorted[k].b);
	int c = k;
	for (int i = 1; i <= k; i++) {
		usedl.insert(sorted[i].idx);
		tot += topics[sorted[i].idx].a;
	}
	for (int i = k + 1; i <= n; i++) {
		unusedr.insert(sorted[i].idx);
	}
	int remaining = s - k;
	for (int i = 1; i <= remaining; i++) {
		int minuu = *unusedr.begin();
		unusedr.erase(unusedr.begin());
		usedr.insert(minuu);
		tot += topics[minuu].a;
	}
	if (tot <= t) return true;
	incm();
	for (int m = k + 1; m <= n; m++) {
		while (c < n && sorted[c + 1].b <= m) {
			if (!add(sorted[c + 1].idx)) return false;
			c++;
			if (tot <= t) return true;
		}
		if (tot <= t) return true;
		if (!incm()) return false;
		if (tot <= t) return true;
	}
	return false;
}

void reset() {
	tot = 0;
	usedl.clear();
	unusedl.clear();
	usedr.clear();
	unusedr.clear();
}

signed main() {
	cin.tie(NULL)->sync_with_stdio(0);
	cin >> q;
	if (q == 10000) istheone = true;
	while (q--) {
		tc++;
		cin >> n >> t;
		reset();
		for (int i = 1; i <= n; i++) {
			int x, y;
			cin >> topics[i].a >> topics[i].b;
			topics[i].idx = i;
			sorted[i] = topics[i];
		}
		//if (istheone) {
		//	if (tc != 4) continue;
		//	cout << n << ' ' << t << '\n';
		//	for (int i = 1; i <= n; i++) {
		//		cout << topics[i].a << ' ' << topics[i].b << '\n';
		//	}
		//	continue;
		//}
		//if (n == 54) {
		//	for (int i = n; i >= 1; i--) {
		//		cout << topics[i].a << ' ' << topics[i].b << '\n';
		//	}
		//	return 0;
		//}
		sort(sorted + 1, sorted + n + 1, cmp);
		int lo = 0, hi = n;
		while (lo != hi) {
			reset();
			int mi = (lo + hi) / 2 + 1;
			if (test(mi)) {
				lo = mi;
			}
			else {
				hi = mi - 1;
			}
		}
		reset();
		test(lo);
		set<int> s;
		for (auto i = usedl.begin(); i != usedl.end(); i++) {
			s.insert(*i);
		}
		for (auto i = usedr.begin(); i != usedr.end(); i++) {
			s.insert(*i);
		}
		cout << lo << '\n';
		cout << s.size() << '\n';
		for (auto i = s.begin(); i != s.end(); i++) {
			cout << *i << ' ';
		}
		cout << '\n';
	}
}

詳細信息

Test #1:

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

input:

2
4 100
20 1
40 4
60 3
30 3
1 5
10 1

output:

2
3
1 2 4 
0
0


result:

ok ok, 2 test cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 160ms
memory: 5932kb

input:

10000
21 1892
174 13
604 15
170 2
413 11
899 2
531 12
651 17
553 9
429 8
837 14
937 12
577 7
532 11
19 2
173 10
165 6
762 15
221 6
945 13
302 19
7 3
54 26066
812 31
432 24
240 37
171 39
204 47
174 30
569 1
467 5
624 42
734 35
907 3
568 23
802 40
991 32
119 13
187 27
739 42
891 14
550 44
374 16
483 1...

output:

7
8
3 9 12 14 15 16 18 21 
53
53
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 
12
12
1 2 4 5 6 7 8 9 12 13 14 15 
5
13
1 8 11 14 15 21 24 28 37 38 40 41 43 
10
11
1 7 9 10 12 15 19 22 27 28 29 
0...

result:

wrong answer actual and declared scores differ: actual = 6, declared = 5 (test case 4)