QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684698 | #8936. Team Arrangement | real_sigma_team# | WA | 0ms | 3792kb | C++23 | 1.3kb | 2024-10-28 15:14:38 | 2024-10-28 15:14:40 |
Judging History
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) {
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];
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3536kb
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: 3584kb
input:
2 1 1 2 2 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3792kb
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: 3740kb
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'