Submission #995436

# Submission time Handle Problem Language Result Execution time Memory
995436 2024-06-09T05:19:35 Z shiomusubi496 Mechanical Doll (IOI18_doll) C++17
53 / 100
123 ms 19200 KB
#include "doll.h"
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)

using namespace std;

using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

void create_circuit(int M, std::vector<int> A) {
    int N = A.size();
    vector<vector<int>> B(M + 1);
    rep (i, N) B[A[i]].push_back(i);
    vector<int> C(M + 1);
    C[0] = A[0];
    int cur = 1;
    int lst = -1;
    vector<pair<int, int>> memo;
    rep2 (i, 1, M + 1) {
        if (B[i].empty()) {
            C[i] = 0;
            continue;
        }
        if (B[i].size() == 1) {
            if (B[i][0] < N - 1) C[i] = A[B[i][0] + 1];
            else lst = i;
            continue;
        }
        int lev = 0;
        while ((1 << lev) < B[i].size()) ++lev;
        if ((1 << lev) != B[i].size()) {
            memo.emplace_back(i, -1);
        }
        int r = 1;
        auto dfs = [&](auto&& dfs, int v, vector<int> p, int lev, bool f) -> void {
            if (lev == 0) {
                if (p.empty()) {
                    if (f) memo.back().second = v;
                    else C[v] = r;
                }
                else {
                    assert(p.size() == 1);
                    if (p[0] < N - 1) C[v] = A[p[0] + 1];
                    else lst = v;
                }
                return;
            }
            vector<int> p0, p1;
            rep (i, p.size()) {
                if (i % 2 == 0) p0.push_back(p[i]);
                else p1.push_back(p[i]);
            }
            int t = cur++;
            if (r == 1) r = -t;
            C.push_back(0); C.push_back(0);
            C[v] = -t;
            int tmp = C.size();
            dfs(dfs, tmp - 2, p0, lev - 1, false);
            dfs(dfs, tmp - 1, p1, lev - 1, f);
        };
        dfs(dfs, i, B[i], lev, true);
        if ((1 << lev) != B[i].size()) memo.back().first = r;
    }
    {
        if (memo.empty()) C[lst] = 0;
        else {
            C[lst] = memo[0].first;
            rep (i, memo.size() - 1) {
                C[memo[i].second] = memo[i + 1].first;
            }
            C[memo.back().second] = 0;
        }
    }
    vector<int> X(cur - 1), Y(cur - 1);
    rep (i, cur - 1) {
        X[i] = C[M + 1 + i * 2];
        Y[i] = C[M + 1 + i * 2 + 1];
    }
    C.resize(M + 1);
    answer(C, X, Y);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:37:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         while ((1 << lev) < B[i].size()) ++lev;
      |                ~~~~~~~~~~~^~~~~~~~~~~~~
doll.cpp:38:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         if ((1 << lev) != B[i].size()) {
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~
doll.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         if ((1 << lev) != B[i].size()) memo.back().first = r;
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 19 ms 6492 KB Output is correct
3 Correct 16 ms 5336 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 25 ms 7656 KB Output is correct
7 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 19 ms 6492 KB Output is correct
3 Correct 16 ms 5336 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 25 ms 7656 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 38 ms 7760 KB Output is correct
9 Correct 33 ms 8904 KB Output is correct
10 Correct 55 ms 11704 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 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 19 ms 6492 KB Output is correct
3 Correct 16 ms 5336 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 6 ms 3932 KB Output is correct
6 Correct 25 ms 7656 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 38 ms 7760 KB Output is correct
9 Correct 33 ms 8904 KB Output is correct
10 Correct 55 ms 11704 KB Output is correct
11 Correct 0 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 69 ms 13292 KB Output is correct
15 Correct 37 ms 7632 KB Output is correct
16 Correct 72 ms 11252 KB Output is correct
17 Correct 1 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 66 ms 13764 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 42 ms 6376 KB Output is correct
3 Partially correct 79 ms 11592 KB Output is partially correct
4 Partially correct 77 ms 12744 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 348 KB Output is partially correct
2 Correct 42 ms 6376 KB Output is correct
3 Partially correct 79 ms 11592 KB Output is partially correct
4 Partially correct 77 ms 12744 KB Output is partially correct
5 Partially correct 111 ms 14896 KB Output is partially correct
6 Partially correct 97 ms 17772 KB Output is partially correct
7 Partially correct 88 ms 17204 KB Output is partially correct
8 Partially correct 123 ms 18436 KB Output is partially correct
9 Partially correct 60 ms 12136 KB Output is partially correct
10 Partially correct 96 ms 17460 KB Output is partially correct
11 Partially correct 96 ms 19200 KB Output is partially correct
12 Partially correct 79 ms 12572 KB Output is partially correct
13 Partially correct 58 ms 11700 KB Output is partially correct
14 Partially correct 58 ms 11324 KB Output is partially correct
15 Partially correct 54 ms 10816 KB Output is partially correct
16 Partially correct 2 ms 600 KB Output is partially correct
17 Partially correct 51 ms 9904 KB Output is partially correct
18 Partially correct 52 ms 9912 KB Output is partially correct
19 Partially correct 55 ms 10612 KB Output is partially correct
20 Partially correct 75 ms 14216 KB Output is partially correct
21 Partially correct 90 ms 16604 KB Output is partially correct
22 Partially correct 73 ms 12916 KB Output is partially correct