Submission #983674

# Submission time Handle Problem Language Result Execution time Memory
983674 2024-05-15T22:28:48 Z mariaclara Mechanical Doll (IOI18_doll) C++17
100 / 100
97 ms 12180 KB
#include "doll.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 4e5+5; 
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

int N;
vector<int> ans, S_x, S_y, state;
int create(int qnt) {
    if(qnt == 1) return 1;
    int a = create(qnt/2), b = create(qnt/2);
    S_x.pb(a);
    S_y.pb(b);
    return -sz(S_y);
}

void create_circuit(int M, vector<int> A) {
    A.pb(0);
    N = sz(A);
    
    vector<int> pot;
    for(int i = 20; i >= 0; i--)
        if(N >= (1<<i)) pot.pb(i), N -= (1<<i);

    N = sz(A);

    reverse(all(pot));

    for(int i = 0, last = 0; i < sz(pot); i++) {
        int k = create((1<<pot[i]));
        if(i > 0) {
            S_x.pb(k);
            S_y.pb(last);
            k = -sz(S_x);
        }
        if(i == sz(pot)-1) break;
        int add = pot[i+1] - pot[i] - !!i;
        while(add--) {
            S_y.pb(k);
            S_x.pb(-sz(S_y));
            k = -sz(S_x);
        }
        last = -sz(S_x);
    }

    int S = sz(S_x);
    vector<int> ans(M+1, -S), state(S,0);

    for(int i = 0; i < S; i++)
        if(S_x[i] == -i-1) S_x[i] = -S;

    // for(int i = 0; i < S; i++)
    //     cout << S_x[i] << " " << S_y[i] << endl;

    int x = -S, qtd = 0;
    while(qtd < N) {
        if(state[-x-1] == 0) {
            state[-x-1] = 1;
            if(S_x[-x-1] == 1) S_x[-x-1] = A[qtd], qtd++, x = -S;
            else x = S_x[-x-1]; 
        } 
        else {
            state[-x-1] = 0;
            if(S_y[-x-1] == 1) S_y[-x-1] = A[qtd], qtd++, x = -S;
            else x = S_y[-x-1]; 
        }
    }

    return answer(ans, S_x, S_y);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 32 ms 4840 KB Output is correct
3 Correct 30 ms 4584 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 9 ms 1372 KB Output is correct
6 Correct 45 ms 6724 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 32 ms 4840 KB Output is correct
3 Correct 30 ms 4584 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 9 ms 1372 KB Output is correct
6 Correct 45 ms 6724 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 58 ms 8160 KB Output is correct
9 Correct 61 ms 8820 KB Output is correct
10 Correct 97 ms 12180 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 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 32 ms 4840 KB Output is correct
3 Correct 30 ms 4584 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 9 ms 1372 KB Output is correct
6 Correct 45 ms 6724 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 58 ms 8160 KB Output is correct
9 Correct 61 ms 8820 KB Output is correct
10 Correct 97 ms 12180 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 440 KB Output is correct
14 Correct 88 ms 11488 KB Output is correct
15 Correct 61 ms 7540 KB Output is correct
16 Correct 89 ms 11308 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 90 ms 11836 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 5564 KB Output is correct
3 Correct 51 ms 5604 KB Output is correct
4 Correct 80 ms 8500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 5564 KB Output is correct
3 Correct 51 ms 5604 KB Output is correct
4 Correct 80 ms 8500 KB Output is correct
5 Correct 83 ms 11056 KB Output is correct
6 Correct 85 ms 10544 KB Output is correct
7 Correct 86 ms 10660 KB Output is correct
8 Correct 81 ms 10312 KB Output is correct
9 Correct 52 ms 6264 KB Output is correct
10 Correct 83 ms 10296 KB Output is correct
11 Correct 86 ms 9872 KB Output is correct
12 Correct 53 ms 6516 KB Output is correct
13 Correct 55 ms 7024 KB Output is correct
14 Correct 57 ms 7284 KB Output is correct
15 Correct 57 ms 7284 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 59 ms 6984 KB Output is correct
18 Correct 53 ms 6512 KB Output is correct
19 Correct 53 ms 6520 KB Output is correct
20 Correct 83 ms 10040 KB Output is correct
21 Correct 85 ms 9780 KB Output is correct
22 Correct 84 ms 9788 KB Output is correct