답안 #430070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430070 2021-06-16T11:18:26 Z KoD Ancient Machine (JOI21_ancient_machine) C++17
5 / 100
55 ms 6680 KB
#include <bits/stdc++.h>
#include "Anna.h"

namespace {

using ll = long long;
template <class T> using Vec = std::vector<T>;

ll encode(const std::array<int, 63>& arr) {
    std::array<std::array<ll, 2>, 2> dp{};
    dp[0][0] = 1;
    for (const auto x : arr) {
        std::array<std::array<ll, 2>, 2> next{};
        for (const int i : {0, 1}) {
            for (const int j : {0, 1}) {
                for (const int k : {0, 1}) {
                    if ((!i and x < k) or j + k == 2) {
                        continue;
                    }
                    next[i || (k < x)][k] += dp[i][j];
                }
            }
        }
        dp = std::move(next);
    }
    return dp[1][0] + dp[1][1];
}

}

void Anna(int N, Vec<char> S) {
    int idx = 0;
    while (idx < N and S[idx] != 'X') {
        idx += 1;
    }
    for (int i = 0; i < 17; ++i) {
        Send(idx >> i & 1);
    }
    Vec<int> seq(N);
    for (int i = idx + 1; i < N; ++i) {
        if (S[i] == 'Z' and (i + 1 == N or S[i + 1] != 'Z')) {
            seq[i] = 1;
        }
    }
    for (int l = 0; l < N; l += 63) {
        std::array<int, 63> arr;
        for (int i = 0; i < 63; ++i) {
            arr[l + i] = (l + i >= N ? 0 : seq[l + i]);
        }
        const ll x = encode(arr);
        for (int i = 0; i < 44; ++i) {
            Send(x >> i & 1);
        }
    }
}
#include <bits/stdc++.h>
#include "Bruno.h"

namespace {

using ll = long long;
template <class T> using Vec = std::vector<T>;

constexpr std::array<ll, 63> FIB = [] {
    std::array<ll, 63> ret{};
    ret[0] = 1;
    ret[1] = 2;
    for (int i = 2; i < 63; ++i) {
        ret[i] = ret[i - 1] + ret[i - 2];
    }
    return ret;
}();

std::array<int, 63> decode(ll x) {
    std::array<int, 63> ret{};
    int idx = 0;
    while (idx < 63) {
        if (x >= FIB[62 - idx]) {
            x -= FIB[62 - idx];
            ret[idx] = 1;
            idx += 2;
        } else {
            idx += 1;
        }
    }
    return ret;
}

}  // namespace

void Bruno(int N, int L, Vec<int> A) {
    int Xpos = 0;
    for (int i = 0; i < 17; ++i) {
        Xpos |= A[i] << i;
    }
    int idx = 0;
    Vec<int> vec;
    for (int i = 17; i < L; i += 44) {
        ll x = 0;
        for (int k = 0; k < 44; ++k) {
            x |= (ll) A[i + k] << k;
        }
        for (const auto y : decode(x)) {
            if (y) {
                vec.push_back(idx);
            }
            idx += 1;
        }
    }
    Vec<int> removed(N);
    for (const auto i : vec) {
        for (int j = i - 1; j > Xpos; --j) {
            Remove(j);
            removed[j] = true;
        }
        Remove(i);
        removed[i] = true;
        Xpos = i;
    }
    for (int i = 0; i < N; ++i) {
        if (!removed[i]) {
            Remove(i);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 484 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 488 KB Output is correct
7 Correct 1 ms 488 KB Output is correct
8 Correct 1 ms 488 KB Output is correct
9 Correct 1 ms 488 KB Output is correct
10 Correct 1 ms 488 KB Output is correct
11 Correct 1 ms 488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 6680 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -