# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
354209 | valerikk | Cheerleaders (info1cup20_cheerleaders) | C++11 | 106 ms | 1732 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long count_inv(vector<int> &a, vector<int> &b) {
int ptr = 0;
long long res = 0;
for (int &x : b) {
while (ptr < a.size() && a[ptr] <= x)
++ptr;
res += (int)a.size() - ptr;
}
return res;
}
const int N = 17;
int n;
int h[1 << N];
long long res[N][2];
void achieve(int mask) {
for (int i = 0; i < n; ++i) {
int pos = (n - 1 + i) % n;
if ((mask >> pos) & 1) cout << 1;
cout << 2;
}
cout << endl;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < (1 << n); ++i)
cin >> h[i];
for (int t = 1; t <= n; ++t) {
for (int i = 0; i + (1 << t) <= (1 << n); i += (1 << t)) {
vector<int> a, b;
for (int j = 0; j < (1 << (t - 1)); ++j) {
a.push_back(h[i + j]);
b.push_back(h[i + j + (1 << (t - 1))]);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
res[t - 1][0] += count_inv(a, b);
res[t - 1][1] += count_inv(b, a);
}
}
int mask = 0;
long long ans = 0;
for (int i = 0; i < n; ++i) {
if (res[i][0] > res[i][1])
mask ^= (1 << i);
ans += min(res[i][0], res[i][1]);
}
cout << ans << endl;
achieve(mask);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |