| Task: | Yhdistelmät |
| Sender: | Metabolix |
| Submission time: | 2025-11-29 12:48:32 +0200 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:17:32: error: use of deleted function 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = __int128 unsigned; _Tp = int; _Hash = std::hash<__int128 unsigned>; _Pred = std::equal_to<__int128 unsigned>; _Alloc = std::allocator<std::pair<const __int128 unsigned, int> >]'
17 | unordered_map<bits_t, int> hinnat;
| ^~~~~~
In file included from /usr/include/c++/11/unordered_map:47,
from /usr/include/c++/11/functional:61,
from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
from /usr/include/c++/11/algorithm:74,
from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
from input/code.cpp:1:
/usr/include/c++/11/bits/unordered_map.h:141:7: note: 'std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map() [with _Key = __int128 unsigned; _Tp = int; _Hash = std::hash<__i...Code
#include <bits/stdc++.h>
using namespace std;
typedef __uint128_t bits_t;
int popcount(bits_t x) {
return __builtin_popcountll((uint64_t)x) + __builtin_popcountll((uint64_t)(x >> 64));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
unordered_map<bits_t, int> hinnat;
for (int i = 1; i <= n; ++i) {
int hinta;
cin >> hinta;
hinnat[(bits_t(1) << i)] = hinta;
}
unordered_map<bits_t, int> palkkiot;
for (int i = 0; i < m; ++i) {
bits_t yhdistelmä = 0;
int k, x;
cin >> k >> x;
for (int j = 0; j < k; ++j) {
int indeksi;
cin >> indeksi;
yhdistelmä |= (bits_t(1) << indeksi);
}
palkkiot[yhdistelmä] = x;
}
auto laske_arvo = [&](bits_t yhdistelmä) {
int arvo = 0;
for (int i = 0; i < n; ++i) {
if (yhdistelmä & (bits_t(1) << i)) {
arvo -= hinnat[bits_t(1) << i];
}
}
for (const auto& [palkkio_yhdistelmä, palkkio] : palkkiot) {
if ((yhdistelmä & palkkio_yhdistelmä) == palkkio_yhdistelmä) {
arvo += palkkio;
}
}
return arvo;
};
bits_t paras_yhdistelmä = 0;
int maksimi_arvo = INT_MIN;
for (bits_t yhdistelmä = 0; yhdistelmä < (bits_t(1) << n); ++yhdistelmä) {
int arvo = laske_arvo(yhdistelmä);
if (arvo > maksimi_arvo) {
paras_yhdistelmä = yhdistelmä;
maksimi_arvo = arvo;
}
}
cout << maksimi_arvo << "\n";
cout << popcount(paras_yhdistelmä) << "\n";
for (int i = 0; i < n; ++i) {
if (paras_yhdistelmä & (bits_t(1) << i)) {
cout << i << " ";
}
}
cout << "\n";
}
