제출 #370040

#제출 시각아이디문제언어결과실행 시간메모리
370040KoDUnscrambling a Messy Bug (IOI16_messy)C++17
100 / 100
3 ms632 KiB
#include <bits/stdc++.h> #include "messy.h" template <class T> using Vec = std::vector<T>; Vec<int> restore_permutation(int n, int w, int r) { { std::queue<std::pair<int, int>> que; que.emplace(0, n); while (!que.empty()) { const auto left = que.front().first; const auto right = que.front().second; que.pop(); if (right - left == 1) { continue; } const auto mid = (left + right) / 2; std::string add(n, '1'); std::fill(add.begin() + left, add.begin() + right, '0'); for (int i = mid; i < right; ++i) { add[i] = '1'; add_element(add); add[i] = '0'; } que.emplace(left, mid); que.emplace(mid, right); } } compile_set(); Vec<int> ret(n); { std::queue<std::tuple<int, int, Vec<int>>> que; { Vec<int> tmp(n); std::iota(tmp.begin(), tmp.end(), 0); que.emplace(0, n, std::move(tmp)); } while (!que.empty()) { const auto left = std::get<0>(que.front()); const auto right = std::get<1>(que.front()); const auto idx = std::get<2>(que.front()); que.pop(); if (right - left == 1) { for (const auto i: idx) { ret[i] = left; } continue; } std::string check(n, '1'); for (const auto x: idx) { check[x] = '0'; } const auto mid = (left + right) / 2; Vec<int> v1, v2; for (const auto x: idx) { check[x] = '1'; if (check_element(check)) { v2.push_back(x); } else { v1.push_back(x); } check[x] = '0'; } que.emplace(left, mid, std::move(v1)); que.emplace(mid, right, std::move(v2)); } } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...