답안 #1016340

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1016340 2024-07-07T20:29:34 Z Unforgettablepl 자동 인형 (IOI18_doll) C++17
53 / 100
109 ms 15060 KB
#include <bits/stdc++.h>
using namespace std;

enum {
    EXIT = 2000000,
};

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

void create_circuit(int M, vector<int> A) {    
    int N = A.size();
    vector<int> C(M + 1);
    vector<int> X(2*N),Y(2*N);
    vector<vector<int>> nextoccurences(M+1);
    A.emplace_back(EXIT);
    for(int i=0;i<N;i++)nextoccurences[A[i]].emplace_back(A[i+1]);
    int S = 0;
    for(int i=1;i<=M;i++){
        if(nextoccurences[i].empty())continue;
        int siz = 1;
        while(nextoccurences[i].size()>siz)siz<<=1;
        if(nextoccurences[i].size()==siz)continue;
        while(nextoccurences[i].size()<siz-1)nextoccurences[i].emplace_back(-i);
        nextoccurences[i].emplace_back(0);
    }
    int extraneeded = 0;
    int head = -1;
    pair<bool,int> exitnode;
    function<void(int,vector<int>)> calc = [&](int x,vector<int> targets){
        if(targets.size()==2){
            if(targets[0]==EXIT){
                exitnode = {false,-x};
            } else if(targets[0]==0){
                X[x] = extraneeded;
                extraneeded = head;
            } else if(targets[0]<0){
                X[x] = head;
            } else {
                X[x] = targets[0];
            }
            if(targets[1]==EXIT){
                exitnode = {true,-x};
            } else if(targets[1]==0){
                Y[x] = extraneeded;
                extraneeded = head;
            } else if(targets[1]<0){
                Y[x] = head;
            } else {
                Y[x] = targets[1];
            }
        } else {
            vector<int> odds;
            vector<int> evens;
            for(int i=0;i<targets.size();i++)
                if(i&1)odds.emplace_back(targets[i]);
                else evens.emplace_back(targets[i]);
            X[x] = -(++S);
            calc(S,evens);
            Y[x] = -(++S);
            calc(S,odds);
        }
    };
    for(int i=1;i<=M;i++){
        if(nextoccurences[i].empty())continue;
        if(nextoccurences[i].size()==1){
            if(nextoccurences[i][0]==EXIT){
                exitnode = {false,i};
            } else {
                C[i] = nextoccurences[i][0];
            }
            continue;
        } 
        head = -(++S);
        C[i]=head;
        calc(-head,nextoccurences[i]);
    }
    if(exitnode.second>0){
        C[exitnode.second]=extraneeded;
    } else {
        if(!exitnode.first)X[-exitnode.second]=extraneeded;
        else Y[-exitnode.second]=extraneeded;
    }
    C[0] = A[0];
    X.erase(X.begin());
    Y.erase(Y.begin());
    X.resize(S);
    Y.resize(S);
    answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:21:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         while(nextoccurences[i].size()>siz)siz<<=1;
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~
doll.cpp:22:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         if(nextoccurences[i].size()==siz)continue;
      |            ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
doll.cpp:23:39: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         while(nextoccurences[i].size()<siz-1)nextoccurences[i].emplace_back(-i);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
doll.cpp: In lambda function:
doll.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             for(int i=0;i<targets.size();i++)
      |                         ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 7428 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 23 ms 9428 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 7428 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 23 ms 9428 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 35 ms 8908 KB Output is correct
9 Correct 32 ms 10328 KB Output is correct
10 Correct 47 ms 13232 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 7428 KB Output is correct
3 Correct 15 ms 6484 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 7 ms 3932 KB Output is correct
6 Correct 23 ms 9428 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 35 ms 8908 KB Output is correct
9 Correct 32 ms 10328 KB Output is correct
10 Correct 47 ms 13232 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 51 ms 12616 KB Output is correct
15 Correct 33 ms 8096 KB Output is correct
16 Correct 51 ms 12100 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 55 ms 14148 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Correct 37 ms 7376 KB Output is correct
3 Partially correct 60 ms 10440 KB Output is partially correct
4 Partially correct 67 ms 12608 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 348 KB Output is partially correct
2 Correct 37 ms 7376 KB Output is correct
3 Partially correct 60 ms 10440 KB Output is partially correct
4 Partially correct 67 ms 12608 KB Output is partially correct
5 Partially correct 74 ms 14400 KB Output is partially correct
6 Partially correct 109 ms 14660 KB Output is partially correct
7 Partially correct 82 ms 14404 KB Output is partially correct
8 Partially correct 75 ms 14400 KB Output is partially correct
9 Partially correct 62 ms 10572 KB Output is partially correct
10 Partially correct 99 ms 15060 KB Output is partially correct
11 Partially correct 99 ms 14568 KB Output is partially correct
12 Partially correct 58 ms 9552 KB Output is partially correct
13 Partially correct 53 ms 9548 KB Output is partially correct
14 Partially correct 51 ms 9560 KB Output is partially correct
15 Partially correct 48 ms 9552 KB Output is partially correct
16 Partially correct 2 ms 600 KB Output is partially correct
17 Partially correct 47 ms 8408 KB Output is partially correct
18 Partially correct 48 ms 8352 KB Output is partially correct
19 Partially correct 53 ms 8780 KB Output is partially correct
20 Partially correct 67 ms 12128 KB Output is partially correct
21 Partially correct 81 ms 13376 KB Output is partially correct
22 Partially correct 63 ms 11584 KB Output is partially correct