답안 #603293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
603293 2022-07-23T21:51:52 Z AlperenT 자동 인형 (IOI18_doll) C++17
100 / 100
111 ms 9380 KB
#include <bits/stdc++.h>
#include "doll.h"
 
using namespace std;
 
const int INF = 1e9 + 5;
 
void create_circuit(int m, vector<int> a) {
    int n, k;
 
    n = a.size(), k = __lg(n);

    if(k == 0){
        vector<int> c(m + 1, 0);

        c[0] = a[0];

        return answer(c, {}, {});
    }
 
    vector<int> c(m + 1), x(n + k + 2, INF), y(n + k + 2, INF);
 
    for(int i = 0; i <= m; i++) c[i] = -1;
 
    int cur = k + 2;
 
    for(int i = k; i >= 0; i--){
        if(n & (1 << i)){
            x[(k - i) + 1] = -cur;
            y[(k - i) + 1] = (i == 0 ? -cur : -((k - i) + 2));
 
            for(int len = 0; len < i - 1; len++){
                for(int j = 0; j < (1 << len); j++){
                    x[cur] = -(cur + (1 << len) + j);
 
                    y[cur] = -(cur + (1 << len) + 1 + j);
 
                    cur++;
                }
            }
 
            cur += (1 << i) / 2;
        }
        else{
            x[(k - i) + 1] = -1;
            y[(k - i) + 1] = (i == 0 ? 0 : -((k - i) + 2));
        }
    }
 
    if(n & 1) y[-x[k + 1]] = 0;
 
    vector<char> where(n + k + 2, 'X');
 
    int v = -1;
 
    for(int i = 0; i < n; i++){
        if(v > 0) v = c[v];
 
        while(v < 0){
            if(where[-v] == 'X'){
                where[-v] = 'Y';
 
                if(x[-v] == INF) x[-v] = a[i];
 
                v = x[-v];
            }
            else if(where[-v] == 'Y'){
                where[-v] = 'X';
                
                if(y[-v] == INF) y[-v] = a[i];
 
                v = y[-v];
            }
        }
    }

    while(x.back() == INF && y.back() == INF) x.pop_back(), y.pop_back();
 
    for(auto &i : x) if(i == INF) i = -1;
    for(auto &i : y) if(i == INF) i = -1;
 
    x.erase(x.begin());
    y.erase(y.begin());
 
    answer(c, x, y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 3540 KB Output is correct
3 Correct 34 ms 3212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 53 ms 4660 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 3540 KB Output is correct
3 Correct 34 ms 3212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 53 ms 4660 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 66 ms 6224 KB Output is correct
9 Correct 74 ms 6624 KB Output is correct
10 Correct 111 ms 9380 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 37 ms 3540 KB Output is correct
3 Correct 34 ms 3212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 8 ms 1364 KB Output is correct
6 Correct 53 ms 4660 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 66 ms 6224 KB Output is correct
9 Correct 74 ms 6624 KB Output is correct
10 Correct 111 ms 9380 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 100 ms 8944 KB Output is correct
15 Correct 68 ms 5968 KB Output is correct
16 Correct 98 ms 8780 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 110 ms 9136 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 65 ms 4536 KB Output is correct
3 Correct 59 ms 4552 KB Output is correct
4 Correct 89 ms 6696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 65 ms 4536 KB Output is correct
3 Correct 59 ms 4552 KB Output is correct
4 Correct 89 ms 6696 KB Output is correct
5 Correct 98 ms 7224 KB Output is correct
6 Correct 96 ms 6928 KB Output is correct
7 Correct 99 ms 6972 KB Output is correct
8 Correct 96 ms 6860 KB Output is correct
9 Correct 61 ms 4572 KB Output is correct
10 Correct 93 ms 6728 KB Output is correct
11 Correct 90 ms 6696 KB Output is correct
12 Correct 58 ms 4536 KB Output is correct
13 Correct 67 ms 4604 KB Output is correct
14 Correct 61 ms 4732 KB Output is correct
15 Correct 64 ms 4780 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 57 ms 4556 KB Output is correct
18 Correct 70 ms 4552 KB Output is correct
19 Correct 64 ms 4552 KB Output is correct
20 Correct 95 ms 6708 KB Output is correct
21 Correct 101 ms 6704 KB Output is correct
22 Correct 94 ms 6732 KB Output is correct