답안 #725079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725079 2023-04-16T20:12:59 Z piOOE Ancient Machine (JOI21_ancient_machine) C++17
44 / 100
77 ms 10156 KB
#include "Anna.h"
#include <bits/stdc++.h>

using namespace std;

namespace {
    constexpr int k2 = 3;
    constexpr int fib = 2;
    constexpr int LOG = 17;
    using i128 = __int128;
//    using i128 = long long;

    i128 fibonacci[fib + 1];

    void initFib() {
        fibonacci[0] = 1;
        fibonacci[1] = 2;
        for (int x = 2; x <= fib; ++x) {
            fibonacci[x] = fibonacci[x - 1] + fibonacci[x - 2];
        }
    }

    i128 toBase2(vector<int> s) {
        i128 x = 0;
        reverse(s.begin(), s.end());
        for (int c : s) {
            x = x * 2 + c;
        }
        return x;
    }

    i128 toFib(vector<int> x) {
        i128 res = 0;
        int n = x.size();
        assert(n == fib);
        for (int i = 0; i < n; ++i) {
            res += x[i] * fibonacci[n - i - 1];
        }
        return res;
    }

    vector<int> toVectorFromBase2(i128 x) {
        vector<int> res(k2);
        for (int i = 0; i < k2; ++i) {
            res[i] += x >> i & i128(1);
        }
        return res;
    }

    vector<int> toVectorFromFib(i128 x) {
        vector<int> a(fib);
        for (int i = 0; i < fib; ++i) {
            if (x >= fibonacci[fib - i - 1]) {
                a[i] = 1;
            }
            x -= a[i] * fibonacci[fib - i - 1];
        }
        assert(x == 0);
        return a;
    }
}

void Anna(int n, std::vector<char> s) {
    initFib();
    int x = find(s.begin(), s.end(), 'X') - s.begin();
    int z = n - (find(s.rbegin(), s.rend(), 'Z') - s.rbegin()) - 1;

    if (x > z) {
        return;
    }

    vector<int> a(n);

    for (int i = x + 1; i < n; ++i) {
        if (s[i] == 'Z' && (i + 1 == n || s[i + 1] != 'Z')) {
            a[i] = 1;
        }
    }

//    for (int x : a) cout << x;
//    cout << endl;

    for (int i = 0; i < LOG; ++i) {
        Send(x >> i & 1);
    }

    while (a.size() % fib) {
        a.push_back(0);
    }

    for (int i = 0; i < a.size(); i += fib) {
        auto f = toFib(vector(a.begin() + i, a.begin() + i + fib));
        auto res = toVectorFromBase2(f);
//        cout << "f:" << f << endl;
        for (int j = 0; j < k2; ++j) {
            Send(res[j]);
        }
    }
}
#include "Bruno.h"
#include <bits/stdc++.h>

using namespace std;

namespace {
    constexpr int k2 = 3;
    constexpr int fib = 2;
    constexpr int LOG = 17;
    using i128 = __int128;
//    using i128 = long long;
    i128 fibonacci[fib + 1];

    void initFib() {
        fibonacci[0] = 1;
        fibonacci[1] = 2;
        for (int x = 2; x <= fib; ++x) {
            fibonacci[x] = fibonacci[x - 1] + fibonacci[x - 2];
        }
    }

    i128 toBase2(vector<int> s) {
        i128 x = 0;
        reverse(s.begin(), s.end());
        for (int c : s) {
            x = x * 2 + c;
        }
        return x;
    }

    i128 toFib(vector<int> x) {
        i128 res = 0;
        int n = x.size();
        assert(n == fib);
        for (int i = 0; i < n; ++i) {
            res += x[i] * fibonacci[n - i - 1];
        }
        return res;
    }

    vector<int> toVectorFromBase2(i128 x) {
        vector<int> res(k2);
        for (int i = 0; i < k2; ++i) {
            res[i] += x >> i & i128(1);
        }
        return res;
    }

    vector<int> toVectorFromFib(i128 x) {
        vector<int> a(fib);
        for (int i = 0; i < fib; ++i) {
            if (x >= fibonacci[fib - i - 1]) {
                a[i] = 1;
            }
            x -= a[i] * fibonacci[fib - i - 1];
        }
        assert(x == 0);
        return a;
    }
}

void Bruno(int N, int L, std::vector<int> A) {
    initFib();
    if (L == 0) {
        for (int i = 0; i < N; ++i) {
            Remove(i);
        }
        return;
    }

    int fi = 0;

    for (int i = 0; i < LOG; ++i) {
        if (A[i]) {
            fi |= 1 << i;
        }
    }

    assert((L - LOG) % k2 == 0);

    int n = N + (fib - N % fib) % fib;

    vector<int> a(n);

    for (int i = LOG, j = 0; i < L; i += k2, j += fib) {
        auto f = toBase2(vector(A.begin() + i, A.begin() + i + k2));
//        cout << "my f:" << f << endl;
        auto res = toVectorFromFib(f);
        for (int k = j; k < j + fib; ++k) {
            assert(k < n);
            a[k] = res[k - j];
        }
    }

//    for (int x : a) {
//        cout << x;
//    }
//    cout << endl;

    for (int i = 0; i < fi; ++i) {
        Remove(i);
    }

    vector<int> stk{fi};

    for (int i = fi + 1; i < N; ++i) {
        if (a[i]) {
            while (stk.size() > 1) {
                Remove(stk.back());
                stk.pop_back();
            }
            Remove(i);
        } else {
            stk.push_back(i);
        }
    }

    for (int x : stk) {
        Remove(x);
    }
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:91:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (int i = 0; i < a.size(); i += fib) {
      |                     ~~^~~~~~~~~~
Anna.cpp: At global scope:
Anna.cpp:50:17: warning: 'std::vector<int> {anonymous}::toVectorFromFib({anonymous}::i128)' defined but not used [-Wunused-function]
   50 |     vector<int> toVectorFromFib(i128 x) {
      |                 ^~~~~~~~~~~~~~~
Anna.cpp:23:10: warning: '{anonymous}::i128 {anonymous}::toBase2(std::vector<int>)' defined but not used [-Wunused-function]
   23 |     i128 toBase2(vector<int> s) {
      |          ^~~~~~~

Bruno.cpp:41:17: warning: 'std::vector<int> {anonymous}::toVectorFromBase2({anonymous}::i128)' defined but not used [-Wunused-function]
   41 |     vector<int> toVectorFromBase2(i128 x) {
      |                 ^~~~~~~~~~~~~~~~~
Bruno.cpp:31:10: warning: '{anonymous}::i128 {anonymous}::toFib(std::vector<int>)' defined but not used [-Wunused-function]
   31 |     i128 toFib(vector<int> x) {
      |          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 516 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 0 ms 520 KB Output is correct
4 Correct 1 ms 516 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 0 ms 508 KB Output is correct
7 Correct 0 ms 508 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 0 ms 508 KB Output is correct
10 Correct 0 ms 508 KB Output is correct
11 Correct 0 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 68 ms 9252 KB Partially correct
2 Partially correct 63 ms 9688 KB Partially correct
3 Partially correct 63 ms 9780 KB Partially correct
4 Partially correct 64 ms 9620 KB Partially correct
5 Partially correct 68 ms 9596 KB Partially correct
6 Partially correct 62 ms 9584 KB Partially correct
7 Partially correct 64 ms 9708 KB Partially correct
8 Partially correct 65 ms 9612 KB Partially correct
9 Partially correct 67 ms 10084 KB Partially correct
10 Partially correct 73 ms 9656 KB Partially correct
11 Partially correct 72 ms 9996 KB Partially correct
12 Partially correct 62 ms 9612 KB Partially correct
13 Partially correct 69 ms 10028 KB Partially correct
14 Partially correct 73 ms 9684 KB Partially correct
15 Partially correct 65 ms 10012 KB Partially correct
16 Partially correct 69 ms 9520 KB Partially correct
17 Correct 47 ms 6688 KB Output is correct
18 Correct 45 ms 6756 KB Output is correct
19 Correct 47 ms 6764 KB Output is correct
20 Partially correct 61 ms 9572 KB Partially correct
21 Partially correct 67 ms 9744 KB Partially correct
22 Partially correct 69 ms 10156 KB Partially correct
23 Partially correct 65 ms 9748 KB Partially correct
24 Partially correct 62 ms 9604 KB Partially correct
25 Correct 46 ms 6760 KB Output is correct
26 Correct 48 ms 6724 KB Output is correct
27 Correct 44 ms 6764 KB Output is correct
28 Correct 44 ms 6760 KB Output is correct
29 Correct 46 ms 6728 KB Output is correct
30 Correct 49 ms 6748 KB Output is correct
31 Correct 45 ms 6816 KB Output is correct
32 Partially correct 65 ms 9628 KB Partially correct
33 Partially correct 77 ms 9516 KB Partially correct