답안 #387046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387046 2021-04-07T21:00:33 Z SorahISA Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
88 ms 8388 KB
#pragma GCC optimize("Ofast", "unroll-loops")
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

const int ENC = 63;
const int DEC = 44;

int64_t fib[ENC];

void initialize() {
    fib[0] = 1, fib[1] = 2;
    for (int i = 2; i < ENC; ++i) fib[i] = fib[i-1] + fib[i-2];
}

vector<int> compress(vector<int> v) {
    initialize();
    v.resize(v.size() + (ENC - v.size() % ENC) % ENC, 0);
    vector<int> ret(v.size() / ENC * DEC, 0);
    for (int i = 0, p = 0; i < v.size(); i += ENC, p += DEC) {
        int64_t num = 0;
        for (int j = 0, k = ENC-1; j < ENC; ++j, --k) num += v[i+j] * fib[k];
        for (int j = 0, k = DEC-1; j < DEC; ++j, --k) ret[p+j] = num >> k & 1;
    }
    return ret;
}

} // namespace

void Anna(int N, vector<char> S) {
    int flag = -1;
    vector<int> vec(N, 0);
    for (int i = 0; i < N; ++i) {
        if (S[i] == 'X' and flag == -1) flag = i;
        if (S[i] == 'Z' and flag != -1) vec[i] = 1;
        if (i and vec[i-1] and vec[i]) vec[i-1] = 0;
    }
    // cerr << "Original:   "; for (auto x : vec) cerr << x; cerr << "\n";
    vec = compress(vec);
    // cerr << "Compress:   "; for (auto x : vec) cerr << x; cerr << "\n";
    for (int i = 0; i < 20; ++i) vec.eb(flag >> i & 1);
    for (auto x : vec) Send(x);
}

/*
4 X Y X Z
7 X Y X Y Z Y Z
13 X Y Z Y X Z Y Y X Z X Y Z
10 Y Y Y Y Y Y Y Y Y Y
*/
#pragma GCC optimize("Ofast", "unroll-loops")
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

const int ENC = 63;
const int DEC = 44;

int64_t fib[ENC];

void initialize() {
    fib[0] = 1, fib[1] = 2;
    for (int i = 2; i < ENC; ++i) fib[i] = fib[i-1] + fib[i-2];
}

vector<int> decompress(vector<int> v) {
    initialize();
    vector<int> ret(v.size() * ENC / DEC, 0);
    for (int i = 0, p = 0; i < v.size(); i += DEC, p += ENC) {
        int64_t num = 0;
        for (int j = 0, k = DEC-1; j < DEC; ++j, --k) num |= (int64_t)v[i+j] << k;
        for (int j = 0, k = ENC-1; j < ENC; ++j, --k) ret[p+j] = num >= fib[k], num %= fib[k];
    }
    return ret;
}

} // namespace

void Bruno(int N, int L, vector<int> A) {
    int lst = 0;
    for (int i = 0; i < 20; ++i) lst |= A[A.size()-20+i] << i;
    if (lst >= N) lst = -1;
    A.resize(A.size() - 20);
    // cerr << "Receive:    "; for (auto x : A) cerr << x; cerr << "\n";
    A = decompress(A), A.resize(N);
    // cerr << "Decompress: "; for (auto x : A) cerr << x; cerr << "\n";
    
    vector<int> tok(N, 1);
    for (int i = 0; i < N; ++i) {
        if (A[i] == 1 and lst == -1) lst = i;
        else if (A[i] == 1) {
            for (int j = i-1; j > lst; --j) tok[j] = 0, Remove(j);
            tok[i] = 0, Remove(i), lst = i;
        }
    }
    for (int i = 0; i < N; ++i) if (tok[i]) Remove(i);
}

Compilation message

Anna.cpp: In function 'std::vector<int> {anonymous}::compress(std::vector<int>)':
Anna.cpp:34:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0, p = 0; i < v.size(); i += ENC, p += DEC) {
      |                            ~~^~~~~~~~~~

Bruno.cpp: In function 'std::vector<int> {anonymous}::decompress(std::vector<int>)':
Bruno.cpp:33:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0, p = 0; i < v.size(); i += DEC, p += ENC) {
      |                            ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 480 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 2 ms 528 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 2 ms 484 KB Output is correct
10 Correct 2 ms 484 KB Output is correct
11 Correct 2 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 8160 KB Output is correct
2 Correct 60 ms 8268 KB Output is correct
3 Correct 66 ms 8144 KB Output is correct
4 Correct 78 ms 8072 KB Output is correct
5 Correct 77 ms 8388 KB Output is correct
6 Correct 65 ms 8228 KB Output is correct
7 Correct 59 ms 8268 KB Output is correct
8 Correct 59 ms 8184 KB Output is correct
9 Correct 66 ms 8300 KB Output is correct
10 Correct 73 ms 8152 KB Output is correct
11 Correct 60 ms 8252 KB Output is correct
12 Correct 60 ms 8288 KB Output is correct
13 Correct 65 ms 8284 KB Output is correct
14 Correct 68 ms 8248 KB Output is correct
15 Correct 65 ms 8196 KB Output is correct
16 Correct 66 ms 8236 KB Output is correct
17 Correct 72 ms 8248 KB Output is correct
18 Correct 66 ms 8088 KB Output is correct
19 Correct 66 ms 8220 KB Output is correct
20 Correct 59 ms 8208 KB Output is correct
21 Correct 72 ms 8224 KB Output is correct
22 Correct 79 ms 8164 KB Output is correct
23 Correct 61 ms 8292 KB Output is correct
24 Correct 61 ms 8240 KB Output is correct
25 Correct 76 ms 8196 KB Output is correct
26 Correct 74 ms 8232 KB Output is correct
27 Correct 69 ms 8260 KB Output is correct
28 Correct 86 ms 8232 KB Output is correct
29 Correct 88 ms 8120 KB Output is correct
30 Correct 66 ms 8304 KB Output is correct
31 Correct 65 ms 8268 KB Output is correct
32 Correct 63 ms 8296 KB Output is correct
33 Correct 65 ms 8308 KB Output is correct