Submission #592550

# Submission time Handle Problem Language Result Execution time Memory
592550 2022-07-09T09:52:41 Z cheissmart Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
66 ms 8060 KB
#include "Anna.h"
#include <vector>
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

namespace {
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
    cerr << to_string(h);
    if(sizeof ...(t)) cerr << ", ";
    DBG(t...);
}
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)

const int INF = 1e9 + 7;

ll fib[70];

}

void Anna(int n, V<char> s) {
    int pos = n - 1;
    for(int i = 0; i < n; i++)
        if(s[i] == 'X') {
            pos = i;
            break;
        }
    for(int i = 0; i < 17; i++)
        Send(pos >> i & 1);

    V<bool> he(n);
    for(int i = pos + 1; i < n; i++)
        if(s[i] == 'Z' && (i + 1 >= n || s[i + 1] != 'Z'))
            he[i] = true;

    fib[0] = 1, fib[1] = 2;
    for(int i = 2; i < 70; i++)
        fib[i] = fib[i - 1] + fib[i - 2];

    for(int i = 0; i < n; i += 63) {
        ll tt = 0;
        for(int j = i; j < n && j < i + 63; j++)
            tt += he[j] * fib[j - i];
        assert(tt < (1LL << 44));
        for(int j = 0; j < 44; j++)
            Send(tt >> j & 1);
    }

}
#include "Bruno.h"
#include <vector>
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

namespace {
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
    cerr << to_string(h);
    if(sizeof ...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7;

ll fib[100];

}

void Bruno(int n, int l, vi a) {
    int pos = 0;
    for(int i = 0; i < 17; i++)
        pos |= a[i] << i;

    int sz = 17;
    vi zs;
    V<bool> be(n);

    fib[0] = 1, fib[1] = 2;
    for(int i = 2; i < 70; i++)
        fib[i] = fib[i - 1] + fib[i - 2];

    for(int i = 0; i < n; i += 63) {
        ll tt = 0;
        for(int j = 0; j < 44; j++)
            tt += a[sz++] * (1LL << j);
        for(int j = 62; j >= 0; j--) {
            if(tt >= fib[j]) {
                be[i + j] = true;
                tt -= fib[j];
            }
        }
        assert(tt == 0);
    }
    for(int i = 0; i < n; i++) if(be[i]) {
        zs.PB(i);
    }

    vi aux;
    for(int i = 0; i <= pos; i++)
        aux.PB(i);
    reverse(ALL(zs));

    for(int i = pos + 1; i < n; i++) {
        if(SZ(zs) && zs.back() == i) {
            zs.pop_back();
            while(aux.back() != pos) {
                Remove(aux.back());
                aux.pop_back();
            }
            Remove(i);
        } else {
            aux.PB(i);
        }
    }
    for(int i:aux)
        Remove(i);

}

Compilation message

Anna.cpp:22:6: warning: 'void {anonymous}::DBG()' defined but not used [-Wunused-function]
   22 | void DBG() { cerr << "]" << _reset << endl; }
      |      ^~~

Bruno.cpp:22:6: warning: 'void {anonymous}::DBG()' defined but not used [-Wunused-function]
   22 | void DBG() { cerr << "]" << _reset << endl; }
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 508 KB Output is correct
2 Correct 0 ms 508 KB Output is correct
3 Correct 0 ms 516 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 0 ms 520 KB Output is correct
6 Correct 0 ms 508 KB Output is correct
7 Correct 1 ms 516 KB Output is correct
8 Correct 0 ms 516 KB Output is correct
9 Correct 2 ms 552 KB Output is correct
10 Correct 2 ms 508 KB Output is correct
11 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 7484 KB Output is correct
2 Correct 55 ms 7856 KB Output is correct
3 Correct 55 ms 7800 KB Output is correct
4 Correct 52 ms 7940 KB Output is correct
5 Correct 54 ms 7952 KB Output is correct
6 Correct 61 ms 7908 KB Output is correct
7 Correct 54 ms 7904 KB Output is correct
8 Correct 57 ms 7856 KB Output is correct
9 Correct 51 ms 7876 KB Output is correct
10 Correct 54 ms 7852 KB Output is correct
11 Correct 62 ms 7764 KB Output is correct
12 Correct 57 ms 7940 KB Output is correct
13 Correct 65 ms 7972 KB Output is correct
14 Correct 60 ms 7868 KB Output is correct
15 Correct 62 ms 7876 KB Output is correct
16 Correct 55 ms 7908 KB Output is correct
17 Correct 62 ms 8052 KB Output is correct
18 Correct 66 ms 7832 KB Output is correct
19 Correct 55 ms 7908 KB Output is correct
20 Correct 48 ms 7940 KB Output is correct
21 Correct 46 ms 7804 KB Output is correct
22 Correct 66 ms 8024 KB Output is correct
23 Correct 47 ms 7972 KB Output is correct
24 Correct 48 ms 7860 KB Output is correct
25 Correct 53 ms 7924 KB Output is correct
26 Correct 53 ms 7920 KB Output is correct
27 Correct 53 ms 8060 KB Output is correct
28 Correct 61 ms 7896 KB Output is correct
29 Correct 56 ms 7872 KB Output is correct
30 Correct 54 ms 7924 KB Output is correct
31 Correct 54 ms 7928 KB Output is correct
32 Correct 54 ms 7852 KB Output is correct
33 Correct 54 ms 7948 KB Output is correct