| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 524147 | LucaIlie | Cheerleaders (info1cup20_cheerleaders) | C++17 | 2017 ms | 2600 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#define MAX_N 17
using namespace std;
struct AIB {
int aib[(1 << MAX_N) + 1];
int query( int i ) {
int s;
s = 0;
while ( i > 0 ) {
s += aib[i];
i -= (i & -i);
}
return s;
}
void update( int i, int x ) {
while ( i <= (1 << MAX_N) ) {
aib[i] += x;
i += (i & -i);
}
}
};
AIB f;
long long countInv( int v[], int n ) {
int i;
long long nrInv;
nrInv = 0;
for ( i = 0; i < n; i++ ) {
nrInv += i - f.query( v[i] );
f.update( v[i] + 1, 1 );
}
for ( i = 0; i < n; i++ )
f.update( v[i] + 1, -1 );
return nrInv;
}
int v[1 << MAX_N], p[1 << MAX_N];
long long sumInv[MAX_N + 1];
vector <int> ans;
int main() {
int n, rot, xr, r, x, l, i, j;
long long minInv, nrInv, newInv;
cin >> n;
for ( i = 0; i < (1 << n); i++ )
cin >> p[i];
if ( n == 0 ) {
cout << 0;
return 0;
}
minInv = (1LL << (2 * n));
xr = rot = 0;
for ( r = 0; r < n; r++ ) {
for ( i = 0; i < (1 << n); i++ )
v[i] = p[i];
for ( l = 0; l <= n; l++ ) {
sumInv[l] = 0;
for ( i = 0; i < (1 << n) - (1 << l) + 1; i += (1 << l) )
sumInv[l] += countInv( p + i, (1 << l) );
}
x = 0;
nrInv = sumInv[n];
for ( l = n - 1; l >= 0; l-- ) {
newInv = sumInv[n] - sumInv[l + 1] + sumInv[l] + ((1LL << (l + n - 1)) - (sumInv[l + 1] - sumInv[l]));
if ( newInv < sumInv[n] ) {
x += (1 << l);
nrInv -= sumInv[n] - newInv;
}
}
if ( nrInv < minInv ) {
minInv = nrInv;
rot = r;
xr = x;
}
for ( i = 0; i < (1 << n); i++ )
v[i] = p[i];
for ( i = 0; i < (1 << n); i++ )
p[((i & 1) << (n - 1)) + (i >> 1)] = v[i];
}
cout << minInv << "\n";
for ( i = 0; i < rot; i++ )
cout << 2;
for ( i = 0; i < n; i++ ) {
cout << 2;
if ( (xr >> i) & 1 )
cout << 1;
}
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... | ||||
