제출 #904324

#제출 시각아이디문제언어결과실행 시간메모리
904324nguyen31hoang08minh2003Turnir (COCI17_turnir)C++17
100 / 100
241 ms25888 KiB
#include <bits/stdc++.h> template<class A, class B> bool maximize(A &a, const B& b) { if (a < b) { a = b; return true; } return false; } template<class A, class B> bool minimize(A &a, const B& b) { if (a > b) { a = b; return true; } return false; } using namespace std; constexpr int MAX_N = 20; int N, n; vector<int> numbers, indices, floorLog2, result; signed main() { #ifdef LOCAL freopen("input.INP", "r", stdin); #endif // LOCAL cin.tie(0) -> sync_with_stdio(0); cout.tie(0); cin >> N; n = 1 << N; numbers.resize(n); result.resize(n); indices.resize(n); floorLog2.resize(n + 1); for (int i = 2; i <= n; ++i) floorLog2[i] = floorLog2[i >> 1] + 1; for (int i = 0; i < n; ++i) { cin >> numbers[i]; indices[i] = i; } sort(indices.begin(), indices.end(), [&](const int &l, const int &r) -> bool { return numbers[l] < numbers[r]; }); for (int l = 0, r = 0, answer; r < n;) { for (; r < n && numbers[indices[l]] == numbers[indices[r]]; ++r); answer = N - floorLog2[r]; for (; l < r; ++l) result[indices[l]] = answer; } for (int i = 0; i < n; ++i) cout << result[i] << ' '; cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...