답안 #591988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591988 2022-07-08T10:44:40 Z PiejanVDC 자동 인형 (IOI18_doll) C++17
53 / 100
124 ms 19272 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;

void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);

void create_circuit(int m, vector<int>a) {
    const int n = (int)a.size();
    a.push_back(0);
    
    vector<vector<int>>v(m+1);

    vector<int>C(m+1, 0);
    C[0] = a[0];
    vector<int>X,Y;

    for(int i = 0 ; i < n ; i++) {
        v[a[i]].push_back(a[i+1]);
    }

    int j = 1;

    for(int i = 1 ; i <= m ; i++) {

        //cout << i << ' ';

        if((int)v[i].size() == 0)
            continue;

        if(v[i].size() == 1) {
            C[i] = v[i][0];
            continue;
        }

        int p = 0;
        while((1 << p) < ((v[i].size())))
            p++;

        vector<int>w;
        if(1) {
            int cnt = /*(v[i].size()&1) + 2*(((v[i].size()+1)/2)&1)*/ (1 << p) - (int)v[i].size(); 
            for(int ii = 0 ; ii < v[i].size()/2 ; ii++)
                w.push_back(v[i][ii]);
            
            for(int ii = 0 ; ii < cnt ; ii++)
                w.push_back(-j);
            
            for(int ii = v[i].size() / 2 ; ii < v[i].size() ; ii++)
                w.push_back(v[i][ii]);
            v[i] = w; 
        }

        vector<int>st(8 * (v[i].size()+1)/2, 0);
        vector<int>rev(8 * (v[i].size()+1)/2);

        C[i] = -j;

        /*for(auto z : v[i])
            cout << z << ' ';*/

        //cout << i << ' ' << v[i].size() << '\n';

        p--;

        for(int l = 0 ; l < v[i].size()/2 ; l++) {
            //cerr << l << ' ';
            int pos = 1, d = 0;
            while(d <= p) {
                if(d < p) {
                    if(!st[pos]) {
                        st[pos] = 1;
                        rev[pos] = j-1;
                        j++;
                        X.push_back(INT_MAX);
                        Y.push_back(INT_MAX);
                    }

                    if(st[pos] == 1) {
                        if(!st[2*pos]) {
                            X[rev[pos]] = (-(j));
                        }
                        st[pos] = 2;
                        pos *= 2;
                    } else {
                        if(!st[2*pos+1]) {
                            Y[rev[pos]] = (-(j));
                        }
                        st[pos] = 1;
                        pos *= 2;
                        pos++;
                    } 

                    d++;
                } else {
                    d++;
                    if(!st[pos]) {
                        st[pos] = 1;
                        rev[pos] = j-1;
                        j++;
                        X.push_back(INT_MAX);
                        Y.push_back(INT_MAX);
                    }
                    if(st[pos] == 1) {
                        X[rev[pos]] = v[i][l];
                        st[pos] = 2;
                    } else {
                        Y[rev[pos]] = v[i][l];
                        st[pos] = 1;
                    }
                }
            } 
        }

        // probeer toch EEN baan te maken en dan vooraleer te beantwoorden alles te checken dat nog geen verbinding heeft en die naar zichzelf laten gaan ofwel X en Y switchen 

        for(int l = v[i].size()/2 ; l < v[i].size() ; l++) {
            int pos = 1, d = 0;
            while(d <= p) {
                if(d < p) {
                    d++;
                    if(st[pos] == 1) {
                        st[pos] = 2;
                        pos *= 2;
                   } else {
                        if(!st[2*pos+1]) {
                            st[pos] = 1;
                            Y[rev[pos]] = -rev[pos] - 1; // watch
                            pos *= 2;
                            continue;
                        }
                        st[pos] = 1;
                        pos *= 2;
                        pos++;
                   }
                } else {
                    d++;
                    if(st[pos] == 1) {
                        assert(0);
                        X[rev[pos]] = -rev[pos]-1;
                        st[pos] = 2;
                    } 
                    st[pos] = 1;
                    Y[rev[pos]] = v[i][l];
                }
            }
        }
    }

    for(int i = 0 ; i < (int)X.size() ; i++) {
        if(Y[i] == INT_MAX)
            Y[i] = -i-1, swap(X[i], Y[i]);
        if(Y[i] == -i-1)
            swap(X[i], Y[i]);
    }

    /*cerr << '\n';

    for(auto z : C)
        cerr << z << ' ';
    cerr << '\n';

    for(auto z : X)
        cerr << z << ' ';
    cerr << '\n';

    for(auto z : Y)
        cerr << z << ' ';
    cerr << '\n';*/

    assert((int)X.size() < 400000);

    answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         while((1 << p) < ((v[i].size())))
      |               ~~~~~~~~~^~~~~~~~~~~~~~~~~
doll.cpp:42:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for(int ii = 0 ; ii < v[i].size()/2 ; ii++)
      |                              ~~~^~~~~~~~~~~~~~~
doll.cpp:48:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |             for(int ii = v[i].size() / 2 ; ii < v[i].size() ; ii++)
      |                                            ~~~^~~~~~~~~~~~~
doll.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for(int l = 0 ; l < v[i].size()/2 ; l++) {
      |                         ~~^~~~~~~~~~~~~~~
doll.cpp:116:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |         for(int l = v[i].size()/2 ; l < v[i].size() ; l++) {
      |                                     ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 28 ms 6352 KB Output is correct
3 Correct 23 ms 5172 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 10 ms 3796 KB Output is correct
6 Correct 42 ms 7736 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 28 ms 6352 KB Output is correct
3 Correct 23 ms 5172 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 10 ms 3796 KB Output is correct
6 Correct 42 ms 7736 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 48 ms 7216 KB Output is correct
9 Correct 66 ms 8508 KB Output is correct
10 Correct 76 ms 11308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 28 ms 6352 KB Output is correct
3 Correct 23 ms 5172 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 10 ms 3796 KB Output is correct
6 Correct 42 ms 7736 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 48 ms 7216 KB Output is correct
9 Correct 66 ms 8508 KB Output is correct
10 Correct 76 ms 11308 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 96 ms 11068 KB Output is correct
15 Correct 57 ms 7076 KB Output is correct
16 Correct 73 ms 10148 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 91 ms 12136 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 55 ms 9136 KB Output is correct
3 Partially correct 97 ms 14904 KB Output is partially correct
4 Partially correct 113 ms 16928 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 212 KB Output is partially correct
2 Correct 55 ms 9136 KB Output is correct
3 Partially correct 97 ms 14904 KB Output is partially correct
4 Partially correct 113 ms 16928 KB Output is partially correct
5 Partially correct 104 ms 13540 KB Output is partially correct
6 Partially correct 108 ms 14136 KB Output is partially correct
7 Partially correct 103 ms 13984 KB Output is partially correct
8 Partially correct 108 ms 14300 KB Output is partially correct
9 Partially correct 88 ms 13360 KB Output is partially correct
10 Partially correct 124 ms 19272 KB Output is partially correct
11 Partially correct 119 ms 14604 KB Output is partially correct
12 Partially correct 74 ms 9712 KB Output is partially correct
13 Partially correct 71 ms 9288 KB Output is partially correct
14 Partially correct 67 ms 9104 KB Output is partially correct
15 Partially correct 65 ms 8908 KB Output is partially correct
16 Partially correct 2 ms 596 KB Output is partially correct
17 Partially correct 59 ms 8136 KB Output is partially correct
18 Partially correct 65 ms 8148 KB Output is partially correct
19 Partially correct 62 ms 8516 KB Output is partially correct
20 Partially correct 82 ms 11288 KB Output is partially correct
21 Partially correct 99 ms 13240 KB Output is partially correct
22 Partially correct 77 ms 11168 KB Output is partially correct