Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 26 pts https://informatics.msk.ru/moodle/mod/statements/view3.php?chapterid=113440#1
- # include <iostream>
- # include <vector>
- void search(size_t &n, size_t &a, size_t &b, size_t &c, size_t &min_ans, std::vector<size_t> cur) {
- if (cur.size() == a + b + c) {
- size_t n_copy = n;
- size_t count_a = 0;
- size_t count_b = 0;
- size_t count_c = 0;
- for (auto i : cur) {
- if (i == 0) {
- count_a++;
- n_copy /= 2;
- } else if (i == 1) {
- count_b++;
- n_copy = (n_copy + 1) / 2;
- } else {
- count_c++;
- if (n_copy != 0) {
- n_copy = (n_copy - 1) / 2;
- }
- }
- }
- if (count_a == a && count_b == b && count_c == c) {
- min_ans = std::min(min_ans, n_copy);
- }
- } else {
- cur.push_back(0);
- search(n, a, b, c, min_ans, cur);
- cur.pop_back();
- cur.push_back(1);
- search(n, a, b, c, min_ans, cur);
- cur.pop_back();
- cur.push_back(2);
- search(n, a, b, c, min_ans, cur);
- }
- }
- int main() {
- size_t n, a, b, c;
- std::cin >> n >> a >> b >> c;
- size_t ans = n;
- std::vector<size_t>cur;
- search(n, a, b, c, ans, cur);
- std::cout << ans;
- return 0;
- }
Add Comment
Please, Sign In to add comment