답안 #1024764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024764 2024-07-16T10:07:02 Z Zicrus 자동 인형 (IOI18_doll) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
#include "doll.h"
using namespace std;
 
typedef long long ll;
 
vector<int> C, X, Y, state;
 
int connect(int a, int bSize, int b, int orig = 0, int mask = 0, int bit = 0) {
    if (!bit && orig) return b;
    
    X.push_back(0);
    Y.push_back(0);
    int id = X.size() - 1;
    bool first = false;
    if (!orig) {
        first = true;
        orig = -X.size();
        mask = bSize - 1;
        if (mask == 0) {
            X.pop_back();
            Y.pop_back();
            return b;
        }
        bit = 1 << (int)log2(mask);
    }
 
    if (mask & bit) {
        X[id] = connect(a, bSize - (1 << ((int)log2(bSize) - 1)), b, orig, mask, bit >> 1);
        Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, ~0, bit >> 1);
    }
    else {
        X[id] = orig;
        Y[id] = connect(a, 1 << ((int)log2(bSize) - 1), b, orig, mask, bit >> 1);
    }
 
    if (first) {
        Y[X.size() - 1] = 0;
    }
 
    return -id - 1;
}
 
void create_circuit(int M, vector<int> A) {
    C = vector<int>(M + 1);
    X = vector<int>(); Y = vector<int>();
    vector<vector<int>> adj(M + 1);
    int prev = 0;
    for(auto &e : A) {
        adj[prev].push_back(e);
        prev = e;
    }
    C[0] = connect(0, A.size(), 1);
    for (int i = 1; i < adj.size(); i++) {
        C[i] = C[0];
    }
 
    state = vector<int>(X.size());
    int pos = 0;
    for (int i = 0; i < A.size(); i++) {
        int prev = pos;
        do {
            prev = pos;
            if (pos >= 0) {
                pos = C[pos];
            }
            else {
                pos = state[-pos - 1] ? Y[-pos - 1] : X[-pos - 1];
                state[-prev - 1] = !state[-prev - 1];
            }
        } while (pos < 0);
        if (pos != A[i]) {
            (!state[-prev - 1] ? Y[-prev - 1] : X[-prev - 1]) = A[i];
            pos = A[i];
        }
    }
 
    answer(C, X, Y);
    return;
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 1; i < adj.size(); i++) {
      |                     ~~^~~~~~~~~~~~
doll.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < A.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB wrong motion
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB wrong motion
2 Halted 0 ms 0 KB -