Submission #1076905

#TimeUsernameProblemLanguageResultExecution timeMemory
1076905belgianbotMechanical Doll (IOI18_doll)C++17
24 / 100
109 ms24436 KiB
#include "doll.h"
#include <bits/stdc++.h>
#define pb push_back
#define fi first 
#define se second

using namespace std;

vector<vector<int>> adj;
vector<int> C, X, Y;

int cnt = -1;
void build(int x) {
    int n = adj[x].size();
    if (n == 1) C[x] = adj[x][0];
    else if (n) {
        C[x] = cnt; cnt--;
        for (int i = n - 1; i > 0; i--) {
            Y.pb(0);
            int first = cnt + 1;
            int time = i - 1;
            pair<int,int> act = {0, 0}, pre = {1, cnt + 1};
            while (time) {
                if (time % pre.fi == 0) {
                    time -= pre.fi;
                    Y.pb(pre.se);
                    X.pb(cnt);
                    act = {pre.fi, cnt};
                    pre.fi *= 2;
                    cnt--;
                }
                else {
                    time -= act.fi;
                    Y.pb(act.se);
                    X.pb(cnt);
                    pre = {act.fi * 2, act.se};
                    act.se = cnt;
                    cnt--;
                }
            }
            X.pb(adj[x][n - 1 - i]);
            auto it = Y.end() + (cnt - first);
            if (i != 1) {
                *it = cnt;
                cnt--;
            }
            else *it = adj[x].back();

        }
    }
    else {
        C[x] = 0;
    }

} 
void create_circuit(int M, vector<int> A) {
    if (M == 1) {
            int N = A.size();
    A.push_back(0);
    vector<int> C(M + 1, INT_MAX), X, Y;
    C[0] = A[0];
 
    int time = N - 1;
    vector<pair<int,int>> fact = {{1, 1}};
    int cnt = -1;
    while (time) {
        int next = 0;
        for (auto x : fact) {
            if (time % x.first == 0) {
                time -= x.first;
                next = x.first;
                X.push_back(x.second);
                if (cnt != -1) Y.push_back(cnt);
                else C[1] = cnt;
                cnt--;
                break;
            }
        }
        for (auto &x : fact) x.first += next;
        fact.push_back({next, cnt + 1});
    }
    if (cnt != -1) Y.push_back(0);
    else C[1] = 0;
    answer(C, X, Y);
    return;
    }
    int N = A.size();
    A.push_back(0);
    C.resize(M + 1);

    adj.resize(M + 1);
    adj[0].pb(A[0]); C[0] = A[0];
    for (int i = 1; i <= N; i++) adj[A[i-1]].pb(A[i]);

    for (int i = 1; i <= M; i++) build(i);

    answer(C, X, Y);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...