답안 #1013910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013910 2024-07-04T08:02:44 Z 김은성(#10850) 자동 인형 (IOI18_doll) C++17
100 / 100
74 ms 23568 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
bool dp[19][1<<18];
int res[1<<18]; //for each switch, desired output
int crit, con[1<<18], swx[1<<18], swy[1<<18], cntsw = 0;
vector<int> seq[1<<18], goal;
int rev(int v, int bit){
    int ans = 0, i;
    for(i=0; i<bit; i++){
        if(v & (1<<i))
            ans |= (1<<(bit-1-i));
    }
    return ans;
}
int setswitch(int bit, int mask){
    if(bit == crit)
        return res[mask];
    if(!dp[bit][mask])
        return -1;
    int now = ++cntsw;
    //printf("bit=%d mask=%d cntsw=%d\n", bit, mask, cntsw);
    swx[now] = setswitch(bit+1, mask*2);
    swy[now] = setswitch(bit+1, mask*2+1);
    return -now;
}
void create_circuit(int M, std::vector<int> A) {
    int N = A.size(), i;
    seq[0].push_back(A[0]);
    for(i=0; i<N-1; i++){
        seq[A[i]].push_back(A[i+1]);
    }
    seq[A[N-1]].push_back(0);
    for(i=0; i<=M; i++){
        if(seq[i].empty())
            con[i] = 0;
        else if(seq[i].size() == 1)
            con[i] = seq[i][0];
        else
            con[i] = -1;
    }
    A.push_back(0);
    for(i=0; i<N; i++){
        if(seq[A[i]].size() >= 2)
            goal.push_back(A[i+1]);
    }
    int sz = goal.size(), bit = 0;
    if(sz==0){
        vector<int> c;
        for(i=0; i<=M; i++)
            c.push_back(con[i]);
        answer(c, {}, {});
        return;
    }
    while((1<<bit) < sz)
        bit++;
    int now = 0;
    memset(res, -1, sizeof(res));
    for(i=0; i<(1<<bit); i++){
        int x = rev(i, bit);
        if(x < (1<<bit)-sz)
            continue;
        dp[bit][x] = 1;
        //printf("res[%d]=%d sz=%d\n", x, goal[now], sz);
        res[x] = goal[now++];
    }
    crit = bit;
    //printf("crit=%d\n", crit);
    for(i=bit-1; i>=0; i--){
        for(int j=0; j<(1<<i); j++){
            dp[i][j] = (dp[i+1][2*j] | dp[i+1][2*j+1]);
            //printf("dp[%d][%d]=%d\n", i, j,dp[i][j]);
        }
    }
    setswitch(0, 0);
    vector<int> c, x, y;
    for(i=0; i<=M; i++){
        //printf("con[%d]=%d\n", i, con[i]);
        c.push_back(con[i]);
    }
    for(i=0; i<cntsw; i++){
        //printf("sw[%d]: %d %d\n", i+1, swx[i+1], swy[i+1]);
        x.push_back(swx[i+1]);
        y.push_back(swy[i+1]);
    }
    answer(c, x, y);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 17 ms 11228 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 20 ms 12756 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 17 ms 11228 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 20 ms 12756 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 40 ms 19256 KB Output is correct
9 Correct 45 ms 18504 KB Output is correct
10 Correct 68 ms 23568 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 17 ms 11228 KB Output is correct
3 Correct 17 ms 10584 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 8 ms 8148 KB Output is correct
6 Correct 20 ms 12756 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 40 ms 19256 KB Output is correct
9 Correct 45 ms 18504 KB Output is correct
10 Correct 68 ms 23568 KB Output is correct
11 Correct 3 ms 7512 KB Output is correct
12 Correct 3 ms 7516 KB Output is correct
13 Correct 3 ms 7516 KB Output is correct
14 Correct 62 ms 22140 KB Output is correct
15 Correct 47 ms 17612 KB Output is correct
16 Correct 61 ms 22048 KB Output is correct
17 Correct 3 ms 7512 KB Output is correct
18 Correct 3 ms 7516 KB Output is correct
19 Correct 3 ms 7516 KB Output is correct
20 Correct 67 ms 22332 KB Output is correct
21 Correct 3 ms 7512 KB Output is correct
22 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 3 ms 7516 KB Output is correct
3 Correct 3 ms 7516 KB Output is correct
4 Correct 3 ms 7600 KB Output is correct
5 Correct 4 ms 7516 KB Output is correct
6 Correct 3 ms 7424 KB Output is correct
7 Correct 3 ms 7516 KB Output is correct
8 Correct 3 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 39 ms 16324 KB Output is correct
3 Correct 48 ms 14964 KB Output is correct
4 Correct 48 ms 18872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7516 KB Output is correct
2 Correct 39 ms 16324 KB Output is correct
3 Correct 48 ms 14964 KB Output is correct
4 Correct 48 ms 18872 KB Output is correct
5 Correct 68 ms 22624 KB Output is correct
6 Correct 74 ms 21004 KB Output is correct
7 Correct 66 ms 21084 KB Output is correct
8 Correct 53 ms 21512 KB Output is correct
9 Correct 38 ms 15040 KB Output is correct
10 Correct 51 ms 19588 KB Output is correct
11 Correct 56 ms 20772 KB Output is correct
12 Correct 39 ms 16584 KB Output is correct
13 Correct 37 ms 17808 KB Output is correct
14 Correct 49 ms 16400 KB Output is correct
15 Correct 50 ms 16644 KB Output is correct
16 Correct 3 ms 8028 KB Output is correct
17 Correct 36 ms 16968 KB Output is correct
18 Correct 37 ms 16972 KB Output is correct
19 Correct 53 ms 15504 KB Output is correct
20 Correct 57 ms 20512 KB Output is correct
21 Correct 55 ms 19776 KB Output is correct
22 Correct 55 ms 19268 KB Output is correct