| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 365113 | Alexandruabcde | Cheerleaders (info1cup20_cheerleaders) | C++14 | 415 ms | 19052 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
constexpr LL NMAX = 18;
LL ans = 0;
vector <LL> moves;
LL p[(1<<NMAX)];
LL N;
LL mat[NMAX][(1<<NMAX)];
LL valbit[2][NMAX];
LL BigSwap (LL x) {
    return (x^(1<<(N-1)));
}
LL BigSplit (LL x) {
    return ((x>>1)|((x&1)<<(N-1)));
}
void Solve (LL cnt_Splits) {
    for (LL i = 0; i < N; ++ i )
        for (LL j = 0; j < 2; ++ j )
            valbit[j][i] = 0;
    for (LL i = 0; i < N; ++ i )
        for (LL j = 0; j < (1<<N); ++ j )
            mat[i][j] = 0;
    for (LL i = 0; i < (1<<N); ++ i ) {
        LL val = p[i];
        for (LL j = 0; j < N; ++ j ) {
            LL bit = ((val>>j)&1);
            valbit[bit][j] += mat[j][((val>>j)^1)];
        }
        for (LL j = 0; j < N; ++ j )
            mat[j][(val>>j)] ++;
    }
    LL xor_val = 0,cnt_Inv = 0;
    for (LL i = 0; i < N; ++ i ) {
        if (i >= N-cnt_Splits && valbit[1][i] < valbit[0][i]) {
            xor_val += (1LL<<i);
            cnt_Inv += 1LL * valbit[1][i];
        }
        else {
            cnt_Inv += 1LL * valbit[0][i];
        }
    }
    if (cnt_Inv < ans) {
        ans = cnt_Inv;
        moves.clear();
        if (N - cnt_Splits - 1 >= 0 && (xor_val&(1LL<<(N-cnt_Splits-1)))) moves.push_back(1);
        for (int i = 1; i <= cnt_Splits; ++ i  ) {
            moves.push_back(2);
            if (N - cnt_Splits - 1 + i >= 0 && (xor_val&(1LL<<(N-cnt_Splits-1+i))))
                moves.push_back(1);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (LL i = 0; i < (1<<N); ++ i ) {
        LL x;
        cin >> x;
        p[x] = i;
    }
    ans = (1LL<<(2*N));
    for (LL i = 0; i <= 2*N; ++ i ) {
        Solve(i);
        for (LL j = 0; j < (1<<N); ++ j )
            p[j] = BigSplit(p[j]);
    }
    cout << ans << '\n';
    for (LL i = 0; i < moves.size(); ++ i )
        cout << moves[i];
    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... | ||||
