Submission #715817

# Submission time Handle Problem Language Result Execution time Memory
715817 2023-03-28T06:45:55 Z Nhoksocqt1 Ancient Machine (JOI21_ancient_machine) C++17
Compilation error
0 ms 0 KB
#ifndef Nhoksocqt1
    #include "Anna.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 100005;

int prv[MAXN], nxt[MAXN];
int pos[MAXN], tmp[MAXN], val[MAXN];

#ifdef Nhoksocqt1

vector<int> sendedMessage;

void Send(int x) {
    sendedMessage.push_back(x);
}

void Remove(int d) {
    cout << "REMOVE AT POS: " << d << '\n';
}

#endif // Nhoksocqt1

void Anna(int n, vector<char> S) {
    for (int i = 0; i < n; ++i) {
        int val = (S[i] != 'X') ? 1 + (S[i] == 'Z') : 0;
        Send(val >> 1 & 1);
        Send(val & 1);
    }
}

void Bruno(int N, int L, vector<int> A) {
    for (int i = 0; i < 2 * N; ++i)
        val[i] = (A[2 * i] << 1) | A[2 * i + 1];

    int l(0), r(N - 1);
    while(l <= r && val[l] != 0) {
        Remove(l);
        ++l;
    }

    while(r >= l && val[r] != 2) {
        Remove(r);
        --r;
    }

    if(l >= r)
        return;

    int nArr(0);
    for (int i = l; i <= r; ++i) {
        while(i < r && val[i] == val[i + 1]) {
            Remove(i);
            ++i;
        }

        pos[++nArr] = i;
    }

    int n(0);
    for (int i = 1; i <= nArr; ++i) {
        if(val[pos[i]] == 1 || i == nArr || val[pos[i + 1]] == 1) {
            tmp[++n] = pos[i];
        } else {
            // val[pos[i + 1]] = 2 - val[pos[i]]
            int j(i + 1);
            while(j <= nArr && val[j] != 1)
                ++j;

            tmp[++n] = (i == 1) ? pos[i] : pos[i + 1];
            for (int k = i; k < j; ++k) {
                if(tmp[n] != pos[k])
                    Remove(pos[k]);
            }

            i = j - 1;
        }
    }

    nArr = n;
    for (int i = 0; i <= nArr; ++i) {
        pos[i] = tmp[i];
        prv[i + 1] = i;
        nxt[i] = i + 1;
    }

    nxt[nArr] = 0;
    for (int i = 1; i > 0; i = nxt[i]) {
        if(prv[i] > 0 && nxt[i] > 0) {
            if(val[pos[prv[i]]] == 0 && val[pos[i]] == 1 && val[pos[nxt[i]]] == 2) {
                Remove(pos[i]);
                prv[nxt[i]] = prv[i];
                nxt[prv[i]] = nxt[i];

                int j(prv[i]);
                if(prv[prv[j]] > 0 && val[pos[prv[prv[j]]]] == 0) {
                    while(prv[prv[j]] > 0 && val[pos[prv[prv[j]]]] == 0) {
                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = prv[j];

                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = prv[j];
                    }
                }

                j = nxt[i];
                if(nxt[j] > 0 && nxt[nxt[j]] > 0 && val[pos[nxt[nxt[j]]]] == 2) {
                    while(nxt[j] > 0 && nxt[nxt[j]] > 0 && val[pos[nxt[nxt[j]]]] == 2) {
                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = nxt[j];

                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = nxt[j];
                    }
                }

                i = prv[j];
            }
        }
    }

    for (int i = nxt[0]; i > 0; i = nxt[i])
        Remove(pos[i]);
}

#ifdef Nhoksocqt1

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    freopen("JOI21MACHINE.inp", "r", stdin);
    freopen("JOI21MACHINE.out", "w", stdout);

    vector<char> s;
    int n;

    cin >> n;
    s.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> s[i];

    Anna(n, s);
    cout << "SENDED MESSAGES: "; for (int it : sendedMessage) cout << it << ' '; cout << '\n';
    Bruno(n, sz(sendedMessage), sendedMessage);

    return 0;
}

#endif // Nhoksocqt1
#ifndef Nhoksocqt1
    #include "Bruno.h"
#endif // Nhoksocqt1
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 100005;

int prv[MAXN], nxt[MAXN];
int pos[MAXN], tmp[MAXN], val[MAXN];

#ifdef Nhoksocqt1

vector<int> sendedMessage;

void Send(int x) {
    sendedMessage.push_back(x);
}

void Remove(int d) {
    cout << "REMOVE AT POS: " << d << '\n';
}

#endif // Nhoksocqt1

void Anna(int n, vector<char> S) {
    for (int i = 0; i < n; ++i) {
        int val = (S[i] != 'X') ? 1 + (S[i] == 'Z') : 0;
        Send(val >> 1 & 1);
        Send(val & 1);
    }
}

void Bruno(int N, int L, vector<int> A) {
    for (int i = 0; i < 2 * N; ++i)
        val[i] = (A[2 * i] << 1) | A[2 * i + 1];

    int l(0), r(N - 1);
    while(l <= r && val[l] != 0) {
        Remove(l);
        ++l;
    }

    while(r >= l && val[r] != 2) {
        Remove(r);
        --r;
    }

    if(l >= r)
        return;

    int nArr(0);
    for (int i = l; i <= r; ++i) {
        while(i < r && val[i] == val[i + 1]) {
            Remove(i);
            ++i;
        }

        pos[++nArr] = i;
    }

    int n(0);
    for (int i = 1; i <= nArr; ++i) {
        if(val[pos[i]] == 1 || i == nArr || val[pos[i + 1]] == 1) {
            tmp[++n] = pos[i];
        } else {
            // val[pos[i + 1]] = 2 - val[pos[i]]
            int j(i + 1);
            while(j <= nArr && val[j] != 1)
                ++j;

            tmp[++n] = (i == 1) ? pos[i] : pos[i + 1];
            for (int k = i; k < j; ++k) {
                if(tmp[n] != pos[k])
                    Remove(pos[k]);
            }

            i = j - 1;
        }
    }

    nArr = n;
    for (int i = 0; i <= nArr; ++i) {
        pos[i] = tmp[i];
        prv[i + 1] = i;
        nxt[i] = i + 1;
    }

    nxt[nArr] = 0;
    for (int i = 1; i > 0; i = nxt[i]) {
        if(prv[i] > 0 && nxt[i] > 0) {
            if(val[pos[prv[i]]] == 0 && val[pos[i]] == 1 && val[pos[nxt[i]]] == 2) {
                Remove(pos[i]);
                prv[nxt[i]] = prv[i];
                nxt[prv[i]] = nxt[i];

                int j(prv[i]);
                if(prv[prv[j]] > 0 && val[pos[prv[prv[j]]]] == 0) {
                    while(prv[prv[j]] > 0 && val[pos[prv[prv[j]]]] == 0) {
                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = prv[j];

                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = prv[j];
                    }
                }

                j = nxt[i];
                if(nxt[j] > 0 && nxt[nxt[j]] > 0 && val[pos[nxt[nxt[j]]]] == 2) {
                    while(nxt[j] > 0 && nxt[nxt[j]] > 0 && val[pos[nxt[nxt[j]]]] == 2) {
                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = nxt[j];

                        Remove(pos[j]);
                        prv[nxt[j]] = prv[j];
                        nxt[prv[j]] = nxt[j];
                        j = nxt[j];
                    }
                }

                i = prv[j];
            }
        }
    }

    for (int i = nxt[0]; i > 0; i = nxt[i])
        Remove(pos[i]);
}

#ifdef Nhoksocqt1

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    freopen("JOI21MACHINE.inp", "r", stdin);
    freopen("JOI21MACHINE.out", "w", stdout);

    vector<char> s;
    int n;

    cin >> n;
    s.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> s[i];

    Anna(n, s);
    cout << "SENDED MESSAGES: "; for (int it : sendedMessage) cout << it << ' '; cout << '\n';
    Bruno(n, sz(sendedMessage), sendedMessage);

    return 0;
}

#endif // Nhoksocqt1

Compilation message

Anna.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Anna.cpp:58:9: error: 'Remove' was not declared in this scope; did you mean 'remove'?
   58 |         Remove(l);
      |         ^~~~~~
      |         remove
Anna.cpp:63:9: error: 'Remove' was not declared in this scope; did you mean 'remove'?
   63 |         Remove(r);
      |         ^~~~~~
      |         remove
Anna.cpp:73:13: error: 'Remove' was not declared in this scope; did you mean 'remove'?
   73 |             Remove(i);
      |             ^~~~~~
      |             remove
Anna.cpp:93:21: error: 'Remove' was not declared in this scope; did you mean 'remove'?
   93 |                     Remove(pos[k]);
      |                     ^~~~~~
      |                     remove
Anna.cpp:111:17: error: 'Remove' was not declared in this scope; did you mean 'remove'?
  111 |                 Remove(pos[i]);
      |                 ^~~~~~
      |                 remove
Anna.cpp:151:9: error: 'Remove' was not declared in this scope; did you mean 'remove'?
  151 |         Remove(pos[i]);
      |         ^~~~~~
      |         remove

Bruno.cpp: In function 'void Anna(int, std::vector<char>)':
Bruno.cpp:47:9: error: 'Send' was not declared in this scope
   47 |         Send(val >> 1 & 1);
      |         ^~~~