답안 #990188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990188 2024-05-29T20:07:41 Z Boomyday 자동 인형 (IOI18_doll) C++17
100 / 100
83 ms 14356 KB
//
// Created by adavy on 5/29/2024.
//
#include <bits/stdc++.h>
using namespace std;

#include "doll.h"


vector<int> gen_pattern(int n){

    if (n==1) return {0,1};

    vector<int> ans = gen_pattern(n-1);
    int sz = ans.size();
    for (int i=0;i<sz;++i) ans[i] *= 2;
    for(int i=0;i<sz;++i) ans.push_back(ans[i]+1);
    return ans;
}

vector<int> X,Y,AA;
int cur_num = 1;

void update(int lev,vector<int> terms,int& pos){
    X.push_back(0); Y.push_back(0);

    int mypos = pos;


    if (terms.size()==2 && lev==2){
        X[mypos] = terms[0]; Y[mypos] = terms[1]; return;
    }
    else if (terms.size()==1 && lev==2){
        Y[mypos] = terms[0]; X[mypos] = -1; return;
    }

    if (terms.size()<=lev/2){
        Y[mypos] = (-++pos - 1);  X[mypos] = -1;  update(lev/2, terms,pos); return;
    }
    vector<int> left,right;
    for(int i=0;i<terms.size();++i){
        if (i<(terms.size()-lev/2)) left.push_back(terms[i]);
        else right.push_back(terms[i]);
    }
    X[mypos] = (-++pos - 1);  update(lev/2, left,pos);
    Y[mypos] = (-++pos - 1); update(lev/2, right,pos);

}
void create_circuit(int M, std::vector<int> A) {
    A.push_back(0);
    AA = A;
    int N = A.size();

    // get smallest power of 2 geq N
    int n = 1, pat_sz = 0;
    while (n < N){ n *= 2;pat_sz+=1;}


    vector<int> pat = gen_pattern(pat_sz);
    // truncate pattern to size N , left truncate!!!

    reverse(pat.begin(),pat.end()); pat.resize(N); reverse(pat.begin(),pat.end());

    // renumber pattern so it only uses digits from 0 to N-1
    vector<pair<int,int>> to_sort;
    for(int i=0;i<N;++i) to_sort.push_back({pat[i],i});
    sort(to_sort.begin(),to_sort.end());
    for(int i=0;i<N;++i) pat[to_sort[i].second] = i;

    vector<int> C(M+1,-1);
    vector<int> pat2(N);
    for(int i=0;i<N;++i) pat2[i] = A[pat[i]];
    // output pat2

    int pos = 0;



    update(n,pat2,pos);
    // output c x and y


    answer(C,X,Y);



}



/*

int main() {
    grader::M =grader:: read_int();
    grader::N = grader::read_int();
    grader::A.resize(grader::N);
    for (int k = 0; k <grader:: N; ++k) {
        grader::A[k] = grader::read_int();
    }

    grader::answered = false;
    create_circuit(grader::M, grader::A);
    if (!grader::answered) {
        grader::wrong_answer("answered not exactly once");
    }
    FILE *file_out = fopen("out.txt", "w");
    fprintf(file_out, "%d\n", grader::S);
    for (int i = 0; i <= grader::M; ++i) {
        fprintf(file_out, "%d\n", grader::IC[i]);
    }
    for (int j = 1; j <= grader::S; ++j) {
        fprintf(file_out, "%d %d\n", grader::IX[j - 1], grader::IY[j - 1]);
    }
    fclose(file_out);
    grader::simulate();
    return 0;
}
*/

Compilation message

doll.cpp: In function 'void update(int, std::vector<int>, int&)':
doll.cpp:37:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |     if (terms.size()<=lev/2){
      |         ~~~~~~~~~~~~^~~~~~~
doll.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<terms.size();++i){
      |                 ~^~~~~~~~~~~~~
doll.cpp:42:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         if (i<(terms.size()-lev/2)) left.push_back(terms[i]);
      |             ~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 28 ms 6416 KB Output is correct
3 Correct 35 ms 5968 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 6 ms 1624 KB Output is correct
6 Correct 40 ms 7880 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 28 ms 6416 KB Output is correct
3 Correct 35 ms 5968 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 6 ms 1624 KB Output is correct
6 Correct 40 ms 7880 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 52 ms 11088 KB Output is correct
9 Correct 63 ms 11348 KB Output is correct
10 Correct 76 ms 14356 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 28 ms 6416 KB Output is correct
3 Correct 35 ms 5968 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 6 ms 1624 KB Output is correct
6 Correct 40 ms 7880 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 52 ms 11088 KB Output is correct
9 Correct 63 ms 11348 KB Output is correct
10 Correct 76 ms 14356 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 81 ms 14228 KB Output is correct
15 Correct 49 ms 11100 KB Output is correct
16 Correct 79 ms 14144 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 75 ms 14292 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 10964 KB Output is correct
3 Correct 46 ms 10832 KB Output is correct
4 Correct 70 ms 13888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 10964 KB Output is correct
3 Correct 46 ms 10832 KB Output is correct
4 Correct 70 ms 13888 KB Output is correct
5 Correct 75 ms 14044 KB Output is correct
6 Correct 73 ms 14144 KB Output is correct
7 Correct 74 ms 14144 KB Output is correct
8 Correct 73 ms 14144 KB Output is correct
9 Correct 46 ms 10836 KB Output is correct
10 Correct 71 ms 13884 KB Output is correct
11 Correct 72 ms 13888 KB Output is correct
12 Correct 64 ms 10828 KB Output is correct
13 Correct 47 ms 11000 KB Output is correct
14 Correct 48 ms 10832 KB Output is correct
15 Correct 48 ms 10924 KB Output is correct
16 Correct 2 ms 956 KB Output is correct
17 Correct 48 ms 8808 KB Output is correct
18 Correct 46 ms 10840 KB Output is correct
19 Correct 50 ms 11856 KB Output is correct
20 Correct 83 ms 14024 KB Output is correct
21 Correct 73 ms 13884 KB Output is correct
22 Correct 71 ms 13884 KB Output is correct