QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#821759#8936. Team ArrangementHugeMouseWA 0ms3680kbC++231.0kb2024-12-19 17:54:162024-12-19 17:54:17

Judging History

This is the latest submission verdict.

  • [2024-12-19 17:54:17]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3680kb
  • [2024-12-19 17:54:16]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> group;
vector<pair<int, int>> a;
vector<int> w;
int ans;

bool check() {
	vector<int> cnt = group;
	int n = group.size(), m = a.size();
	for (int i = 0, j = 0, k; i < n; ++i)
	{
		k = cnt[i];
		while (k--)
		{
			auto &[l, r] = a[j];
			if (l > cnt[i] || r < cnt[i]) return 0;
			++j;
		}
	}
	return 1;
}


void dfs(int cur, int step) {
	if (cur == 0) {
		if (!check()) return;
		int sum = 0;
		for (auto x : group) sum += w[x - 1];
		ans = max(ans, sum);
		return;
	}
	for (int i = step; i <= cur; i++) {
		group.push_back(i);
		dfs(cur - i, i);
		group.pop_back();
	}
}

int main() {
	int n; cin >> n;
	a.resize(n);
	w.resize(n);
	ans = -2e9;
	for (auto &[l, r] : a) cin >> l >> r;
	for (auto &x : w) cin >> x;
	sort(a.begin(), a.end(), [](const auto &x, const auto &y) {
		return x.second < y.second;
	});
	dfs(n, 1);
	if (ans != -2e9) cout << ans << '\n';
	else cout << "impossible\n";
	return 0;
}

详细

Test #1:

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

input:

3
2 3
1 2
2 2
4 5 100

output:

9

result:

ok single line: '9'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

3
1 3
3 3
2 3
1 1 100

output:

100

result:

ok single line: '100'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

3
2 3
1 2
2 2
-100 -200 100000

output:

-300

result:

ok single line: '-300'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3680kb

input:

9
1 4
2 5
3 4
1 5
1 1
2 5
3 5
1 3
1 1
1 1 1 1 1 1 1 1 1

output:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'