QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#684687#8936. Team Arrangementreal_sigma_team#WA 0ms3808kbC++231.3kb2024-10-28 15:12:112024-10-28 15:12:12

Judging History

This is the latest submission verdict.

  • [2024-10-28 15:12:12]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3808kb
  • [2024-10-28 15:12:11]
  • Submitted

answer

#include<bits/stdc++.h>

int main() {
	int n;
	std::cin >> n;
	std::vector<std::pair<int, int>> seg(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> seg[i].first >> seg[i].second;
	}
	std::sort(seg.begin(), seg.end(), [&](auto x, auto y) {
		return x.second < y.second;
	});
	// for (auto [l, r] : seg) std::cout << l << ' ' << r << std::endl;
	std::map<int64_t, int> mp;
	mp[0] = 0;
	for (int i = 1; i <= n; ++i) {
		int w;
		std::cin >> w;
		std::priority_queue<std::pair<int, int64_t>, std::vector<std::pair<int, int64_t>>, std::greater<std::pair<int, int64_t>>> pq;
		for (auto [x, y] : mp) pq.emplace(y, x);
		while (pq.size()) {
			auto [val, msk] = pq.top();
			pq.pop();
			if (mp[msk] < val) continue;
			int64_t add = 0;
			for (int j = 0; j < n && __builtin_popcountll(add) < i; ++j) {
				if ((~msk >> j & 1) && seg[j].first <= i && i <= seg[j].second) add |= 1ll << j;
			}
			if (__builtin_popcountll(add) == i) {
				// std::cout << i << ' ' << msk << ' ' << add << ' ' << val + w << std::endl;
				msk |= add;
				val += w;
				if (!mp.count(msk) || mp[msk] > val) {
					if (msk == 4) std::cout << i << ' ' << val << std::endl;
					mp[msk] = val;
					pq.emplace(val, msk);
				}
			}
		}
	}
	int64_t fin = (1ll << n) - 1;
	if (!mp.count(fin)) std::cout << "impossible";
	else std::cout << mp[fin];
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

input:

2
1 1
2 2
1 1

output:

impossible

result:

ok single line: 'impossible'

Test #4:

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

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

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:

4

result:

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