제출 #365476

#제출 시각아이디문제언어결과실행 시간메모리
365476tfgZalmoxis (BOI18_zalmoxis)C++17
100 / 100
282 ms10476 KiB
#include <iostream> #include <vector> #include <chrono> #include <random> #include <cassert> std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 1001000; int n, k; int a[ms], b[ms]; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cin >> n >> k; for(int i = 0; i < n; i++) { std::cin >> a[i]; } for(int p = 0; p < 30; p++) { int j = 0; for(int i = 0; i < n;) { if(std::abs(a[i]) > p) { b[j++] = a[i++]; } else { int sum = 0; //std::cout << "starting from " << i << std::endl; while(i < n && std::abs(a[i]) <= p) { b[j++] = a[i]; sum += 1 << std::abs(a[i++]); } //std::cout << "sum " << sum << ", ending at " << i << std::endl; sum %= 1 << (p+1); assert(sum == 0 || sum == (1 << p)); if(sum) { b[j++] = -p; k--; } } } n = j; std::swap(a, b); } for(int i = 0; i < n; i++) { if(a[i] >= 0) { std::cout << a[i] << ' '; continue; } std::vector<int> wtf(1, -a[i]); while(!wtf.empty()) { if(k == 0 || wtf.back() == 0) { std::cout << wtf.back() << ' '; wtf.pop_back(); continue; } else { int val = wtf.back(); wtf.pop_back(); wtf.push_back(val-1); wtf.push_back(val-1); k--; } } } std::cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...