답안 #995437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995437 2024-06-09T05:21:25 Z shiomusubi496 자동 인형 (IOI18_doll) C++17
53 / 100
96 ms 17708 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 (p.empty() && !f) {
                C[v] = r;
                return;
            }
            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:73:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         if ((1 << lev) != B[i].size()) memo.back().first = r;
      |             ~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 19 ms 6332 KB Output is correct
3 Correct 14 ms 5208 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 9 ms 3932 KB Output is correct
6 Correct 25 ms 7772 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 19 ms 6332 KB Output is correct
3 Correct 14 ms 5208 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 9 ms 3932 KB Output is correct
6 Correct 25 ms 7772 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 37 ms 7780 KB Output is correct
9 Correct 33 ms 8916 KB Output is correct
10 Correct 59 ms 11600 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 348 KB Output is correct
2 Correct 19 ms 6332 KB Output is correct
3 Correct 14 ms 5208 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 9 ms 3932 KB Output is correct
6 Correct 25 ms 7772 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 37 ms 7780 KB Output is correct
9 Correct 33 ms 8916 KB Output is correct
10 Correct 59 ms 11600 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 70 ms 13400 KB Output is correct
15 Correct 36 ms 6604 KB Output is correct
16 Correct 58 ms 9972 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 62 ms 12476 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB Output is partially correct
2 Correct 43 ms 6572 KB Output is correct
3 Partially correct 66 ms 11592 KB Output is partially correct
4 Partially correct 75 ms 12600 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 0 ms 344 KB Output is partially correct
2 Correct 43 ms 6572 KB Output is correct
3 Partially correct 66 ms 11592 KB Output is partially correct
4 Partially correct 75 ms 12600 KB Output is partially correct
5 Partially correct 84 ms 14892 KB Output is partially correct
6 Partially correct 96 ms 16244 KB Output is partially correct
7 Partially correct 85 ms 15844 KB Output is partially correct
8 Partially correct 90 ms 16944 KB Output is partially correct
9 Partially correct 83 ms 11724 KB Output is partially correct
10 Partially correct 93 ms 16204 KB Output is partially correct
11 Partially correct 91 ms 17708 KB Output is partially correct
12 Partially correct 65 ms 11684 KB Output is partially correct
13 Partially correct 56 ms 10676 KB Output is partially correct
14 Partially correct 55 ms 10452 KB Output is partially correct
15 Partially correct 65 ms 9788 KB Output is partially correct
16 Partially correct 2 ms 600 KB Output is partially correct
17 Partially correct 53 ms 8984 KB Output is partially correct
18 Partially correct 52 ms 9140 KB Output is partially correct
19 Partially correct 54 ms 9580 KB Output is partially correct
20 Partially correct 82 ms 12520 KB Output is partially correct
21 Partially correct 83 ms 15072 KB Output is partially correct
22 Partially correct 73 ms 11308 KB Output is partially correct