QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#630745#8936. Team Arrangementwoodie_0064#WA 0ms3844kbC++141.2kb2024-10-11 20:15:232024-10-11 20:15:24

Judging History

This is the latest submission verdict.

  • [2024-10-11 20:15:24]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3844kb
  • [2024-10-11 20:15:23]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
int n, a[65], ans = -inf;
vector<int> R[65];
void dfs(int sz, vector<int> s, int sum) {
	if(!s.empty() && s.back() < sz) {
		return;
	}
	if(sz == n + 1) {
		ans = max(ans, sum);
		return;
	}
	vector<int> t;
	int i = 0, j = 0;
	while(i < (int)s.size() && j < (int)R[sz].size()) {
		if(s[i] > R[sz][j]) {
			t.push_back(s[i]);
			i++;
		}
		else {
			t.push_back(R[sz][j]);
			j++;
		}
	}
	for(int x = i; x < (int)s.size(); x++) {
		t.push_back(s[x]);
	}
	for(int x = j; x < (int)R[sz].size(); x++) {
		t.push_back(R[sz][x]);
	}
	dfs(sz + 1, t, sum);
	int x = 0;
	while((int)t.size() >= sz) {
		t.resize((int)t.size() - sz);
		x += sz;
		dfs(sz + 1, t, sum + a[x]);
	}
}
int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 1, l, r; i <= n; i++) {
		cin >> l >> r;
		R[l].push_back(r);
	}
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = 1; i <= n; i++) {
		sort(R[i].begin(), R[i].end(), greater<int>());
	}
	dfs(1, vector<int>(0), 0);
	if(ans == -inf) {
		cout << "impossible\n";
	} else {
		cout << ans << '\n';
	}
	return 0;
}

详细

Test #1:

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

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: 3844kb

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: 3560kb

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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: 3556kb

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:

3

result:

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