Submission #1013906

# Submission time Handle Problem Language Result Execution time Memory
1013906 2024-07-04T08:01:12 Z 김은성(#10850) Mechanical Doll (IOI18_doll) C++17
12 / 100
45 ms 30784 KB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
bool dp[18][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);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 20 ms 11496 KB Output is correct
3 Correct 12 ms 12632 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 6 ms 8404 KB Output is correct
6 Correct 25 ms 14804 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 20 ms 11496 KB Output is correct
3 Correct 12 ms 12632 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 6 ms 8404 KB Output is correct
6 Correct 25 ms 14804 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 45 ms 19124 KB Output is correct
9 Correct 42 ms 18504 KB Output is correct
10 Runtime error 34 ms 30784 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 20 ms 11496 KB Output is correct
3 Correct 12 ms 12632 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 6 ms 8404 KB Output is correct
6 Correct 25 ms 14804 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 45 ms 19124 KB Output is correct
9 Correct 42 ms 18504 KB Output is correct
10 Runtime error 34 ms 30784 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7768 KB Output is correct
2 Correct 2 ms 9820 KB Output is correct
3 Correct 2 ms 9820 KB Output is correct
4 Correct 2 ms 7772 KB Output is correct
5 Correct 2 ms 7772 KB Output is correct
6 Correct 2 ms 7772 KB Output is correct
7 Correct 1 ms 7772 KB Output is correct
8 Correct 2 ms 7772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 31 ms 16264 KB Output is correct
3 Runtime error 18 ms 20804 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7772 KB Output is correct
2 Correct 31 ms 16264 KB Output is correct
3 Runtime error 18 ms 20804 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -