답안 #975611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975611 2024-05-05T14:36:19 Z LucaIlie 자동 인형 (IOI18_doll) C++17
100 / 100
108 ms 17816 KB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX_M = 1e5;
const int MAX_L = (1 << 18);
int ord[MAX_L];

vector<int> c, x, y;
int switchid( int x ) {
    return -(x + 1);
}
int idswitch( int x ) {
    return -(x + 1);
}


vector<int> vert;
vector<pair<int, int>> leafs;
int P;

void dfs( int v, int s, int l, bool canCut ) {
    vert.push_back( v );
    if ( canCut && ((s >> l) & 1) ) {
        x[v] = -1;
        if ( l == 0 ) {
            leafs.push_back( { v, 1 } );
            return;
        }
        dfs( v * 2 + 2, s, l - 1, canCut );
        return;
    }
    if ( l == 0 ) {
        leafs.push_back( { v, 0 } );
        leafs.push_back( { v, 1 } );
        return;
    }
    dfs( v * 2 + 1, s, l - 1, canCut );
    dfs( v * 2 + 2, s, l - 1, false );
}

void create_circuit( int m, vector<int> a ) {
    int n = a.size();

    if ( n == 1 ) {
        c.resize( m + 1 );
        c[0] = a[0];
        answer( c, x, y );
        return;
    }

    c.resize( m + 1 );
    a.push_back( 0 );
    c[0] = a[0];

    int p = ceil( log2( n ) );
    x.resize( (1 << p) - 1 );
    y.resize( (1 << p) - 1 );
    for ( int v = 0; v < (1 << (p - 1)) - 1; v++ ) {
        x[v] = switchid( v * 2 + 1 );
        y[v] = switchid( v * 2 + 2 );
    }
    for ( int v = 0; v < (1 << p); v++ ) {
        int c = 0;
        for ( int b = 0; b < p; b++ ) {
            if ((v >> b) & 1 )
                c += (1 << (p - 1 - b));
        }
        ord[v] = c;
    }

    dfs( 0, (1 << p) - n, p - 1, true );

    for ( int i = 1; i <= m; i++ )
        c[i] = -1;

    vector<int> nrml( x.size() );
    for ( int v = 0; v < x.size(); v++ )
        nrml[v] = -1;
    sort( vert.begin(), vert.end() );
    for ( int i = 0; i < vert.size(); i++ )
        nrml[vert[i]] = i;
    vector<int> xaux( vert.size() ), yaux( vert.size() );
    for ( int i = 0; i < vert.size(); i++ ) {
        if ( x[vert[i]] != 0 )
            xaux[i] = switchid( nrml[idswitch( x[vert[i]] )] );
        if ( y[vert[i]] != 0 )
            yaux[i] = switchid( nrml[idswitch( y[vert[i]] )] );
    }

    P = p;
    sort( leafs.begin(), leafs.end(), []( auto c, auto d ) {
        return ord[(c.first - (1 << (P - 1)) + 1) * 2 + c.second] < ord[(d.first - (1 << (P - 1)) + 1) * 2 + d.second];
    } );

    int ind = 1;
    for ( auto leaf: leafs ) {
        int v = nrml[leaf.first];
        if ( leaf.second == 0 )
            xaux[v] = a[ind];
        else
            yaux[v] = a[ind];
        ind++;
    }

    answer( c, xaux, yaux );
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:79:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for ( int v = 0; v < x.size(); v++ )
      |                      ~~^~~~~~~~~~
doll.cpp:82:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for ( int i = 0; i < vert.size(); i++ )
      |                      ~~^~~~~~~~~~~~~
doll.cpp:85:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for ( int i = 0; i < vert.size(); i++ ) {
      |                      ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 37 ms 5968 KB Output is correct
3 Correct 36 ms 6984 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 7 ms 1492 KB Output is correct
6 Correct 53 ms 9276 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 37 ms 5968 KB Output is correct
3 Correct 36 ms 6984 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 7 ms 1492 KB Output is correct
6 Correct 53 ms 9276 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 60 ms 11156 KB Output is correct
9 Correct 71 ms 13684 KB Output is correct
10 Correct 103 ms 17816 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 37 ms 5968 KB Output is correct
3 Correct 36 ms 6984 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 7 ms 1492 KB Output is correct
6 Correct 53 ms 9276 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 60 ms 11156 KB Output is correct
9 Correct 71 ms 13684 KB Output is correct
10 Correct 103 ms 17816 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 448 KB Output is correct
14 Correct 99 ms 17360 KB Output is correct
15 Correct 69 ms 12536 KB Output is correct
16 Correct 108 ms 17060 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 102 ms 17480 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 55 ms 8748 KB Output is correct
3 Correct 64 ms 10664 KB Output is correct
4 Correct 94 ms 14220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 55 ms 8748 KB Output is correct
3 Correct 64 ms 10664 KB Output is correct
4 Correct 94 ms 14220 KB Output is correct
5 Correct 97 ms 15408 KB Output is correct
6 Correct 102 ms 15292 KB Output is correct
7 Correct 97 ms 15404 KB Output is correct
8 Correct 97 ms 14896 KB Output is correct
9 Correct 70 ms 10852 KB Output is correct
10 Correct 97 ms 14968 KB Output is correct
11 Correct 94 ms 14640 KB Output is correct
12 Correct 64 ms 11120 KB Output is correct
13 Correct 59 ms 9288 KB Output is correct
14 Correct 67 ms 11520 KB Output is correct
15 Correct 66 ms 11596 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 59 ms 9036 KB Output is correct
18 Correct 56 ms 9032 KB Output is correct
19 Correct 64 ms 11116 KB Output is correct
20 Correct 97 ms 14636 KB Output is correct
21 Correct 95 ms 14372 KB Output is correct
22 Correct 99 ms 14424 KB Output is correct