답안 #880576

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880576 2023-11-29T16:44:47 Z andrei_boaca 자동 인형 (IOI18_doll) C++17
100 / 100
104 ms 19744 KB
#include "doll.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n;
const int INF=1e9;
vector<int> vecini[100005];
vector<int> C,X,Y;
vector<int> v;
int lft[500005],rgt[500005];
int s;
int state[500005];
int added=0;
int build(int st,int dr,int a,int b)
{
    if(dr<a||st>b)
        return -INF;
    if(st==dr)
        return INF;
    int mij=(st+dr)/2;
    int l=build(st,mij,a,b);
    int r=build(mij+1,dr,a,b);
    s++;
    lft[s]=l;
    rgt[s]=r;
    return -s;
}
int plsmake()
{
    if(v.size()==1)
        return v[0];
    int lg=v.size();
    int L=lg;
    while(__builtin_popcount(L)>1)
        L++;
    int root=build(1,L,L-lg+1,L);
    vector<pii> ord;
    for(int z=1;z<=L;z++)
    {
        int nod=abs(root);
        while(true)
        {
            if(state[nod]==0)
            {
                state[nod]^=1;
                if(lft[nod]==-INF)
                    break;
                if(lft[nod]==INF)
                {
                    ord.push_back({nod,0});
                    break;
                }
                nod=-lft[nod];
                continue;
            }
            else
            {
                state[nod]^=1;
                if(rgt[nod]==-INF)
                    break;
                if(rgt[nod]==INF)
                {
                    ord.push_back({nod,1});
                    break;
                }
                nod=-rgt[nod];
                continue;
            }
        }
    }
    for(int i=0;i<v.size();i++)
    {
        int nod=ord[i].first,dir=ord[i].second;
        if(dir==0)
            lft[nod]=v[i];
        else
            rgt[nod]=v[i];
    }
    return root;
}
void create_circuit(int M, std::vector<int> A)
{
    C.resize(M+1);
    n=A.size();
    C[0]=A[0];
    for(int i=1;i<A.size();i++)
        v.push_back(A[i]);
    v.push_back(0);
    int r=plsmake();
    for(int i=1;i<=M;i++)
        C[i]=r;
    for(int i=1;i<=s;i++)
    {
        if(lft[i]==-INF)
            lft[i]=r;
        X.push_back(lft[i]);
        Y.push_back(rgt[i]);
    }
    answer(C,X,Y);
}

Compilation message

doll.cpp: In function 'int plsmake()':
doll.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:88:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i=1;i<A.size();i++)
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 32 ms 12080 KB Output is correct
3 Correct 34 ms 11788 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 12 ms 7848 KB Output is correct
6 Correct 52 ms 14240 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 32 ms 12080 KB Output is correct
3 Correct 34 ms 11788 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 12 ms 7848 KB Output is correct
6 Correct 52 ms 14240 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 57 ms 15048 KB Output is correct
9 Correct 65 ms 16052 KB Output is correct
10 Correct 94 ms 19556 KB Output is correct
11 Correct 2 ms 6232 KB Output is correct
12 Correct 2 ms 6236 KB Output is correct
13 Correct 1 ms 6428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 32 ms 12080 KB Output is correct
3 Correct 34 ms 11788 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 12 ms 7848 KB Output is correct
6 Correct 52 ms 14240 KB Output is correct
7 Correct 1 ms 4188 KB Output is correct
8 Correct 57 ms 15048 KB Output is correct
9 Correct 65 ms 16052 KB Output is correct
10 Correct 94 ms 19556 KB Output is correct
11 Correct 2 ms 6232 KB Output is correct
12 Correct 2 ms 6236 KB Output is correct
13 Correct 1 ms 6428 KB Output is correct
14 Correct 91 ms 18704 KB Output is correct
15 Correct 57 ms 14396 KB Output is correct
16 Correct 89 ms 18520 KB Output is correct
17 Correct 2 ms 6236 KB Output is correct
18 Correct 2 ms 6236 KB Output is correct
19 Correct 2 ms 6236 KB Output is correct
20 Correct 104 ms 19744 KB Output is correct
21 Correct 2 ms 6236 KB Output is correct
22 Correct 1 ms 6340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 2 ms 6236 KB Output is correct
3 Correct 2 ms 6236 KB Output is correct
4 Correct 2 ms 6236 KB Output is correct
5 Correct 2 ms 6232 KB Output is correct
6 Correct 2 ms 6236 KB Output is correct
7 Correct 2 ms 6236 KB Output is correct
8 Correct 2 ms 6428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 50 ms 13528 KB Output is correct
3 Correct 55 ms 13624 KB Output is correct
4 Correct 85 ms 17176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6236 KB Output is correct
2 Correct 50 ms 13528 KB Output is correct
3 Correct 55 ms 13624 KB Output is correct
4 Correct 85 ms 17176 KB Output is correct
5 Correct 89 ms 18456 KB Output is correct
6 Correct 88 ms 18188 KB Output is correct
7 Correct 89 ms 18096 KB Output is correct
8 Correct 89 ms 18380 KB Output is correct
9 Correct 53 ms 13624 KB Output is correct
10 Correct 89 ms 17932 KB Output is correct
11 Correct 97 ms 17472 KB Output is correct
12 Correct 56 ms 13876 KB Output is correct
13 Correct 53 ms 14016 KB Output is correct
14 Correct 58 ms 14296 KB Output is correct
15 Correct 58 ms 14396 KB Output is correct
16 Correct 3 ms 6488 KB Output is correct
17 Correct 51 ms 13900 KB Output is correct
18 Correct 57 ms 13664 KB Output is correct
19 Correct 61 ms 13876 KB Output is correct
20 Correct 85 ms 17684 KB Output is correct
21 Correct 87 ms 17404 KB Output is correct
22 Correct 88 ms 17680 KB Output is correct