Submission #715835

# Submission time Handle Problem Language Result Execution time Memory
715835 2023-03-28T07:28:20 Z Nhoksocqt1 Ancient Machine (JOI21_ancient_machine) C++17
30 / 100
80 ms 11576 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);
    }
}
 
#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 Bruno(int N, int L, vector<int> A) {
    for (int i = 0; i < 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[pos[j]] != 1)
                ++j;

            int posX = (val[pos[i]] == 0 ? pos[i] : pos[i + 1]);
            int posZ = (val[pos[i]] == 0 ? pos[i + 1] : pos[i]);
            tmp[++n] = (i == 1) ? posX : posZ;
            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;
        //cout << pos[i] << " \n"[i == nArr];
    }

    nxt[nArr] = 0;
    int CNT(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) {
                ++CNT;
                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) {
                        ++CNT;
                        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];
                int tmp(j);
                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) {
                        ++CNT;
                        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];
                    }
                }

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

                i = prv[j];
            }
        }
    }

    //int cntNow(0); for (int i = l; i <= r; ++i) cntNow += ((i == l || val[i - 1] != val[i]) && val[i] == 1);
    //cout << "COUNT PAIRS: " << CNT << " ANS: " << cntNow << '\n';

    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

Bruno.cpp: In function 'void Bruno(int, int, std::vector<int>)':
Bruno.cpp:128:21: warning: unused variable 'tmp' [-Wunused-variable]
  128 |                 int tmp(j);
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 0 ms 520 KB Output is correct
4 Correct 0 ms 648 KB Output is correct
5 Correct 1 ms 520 KB Output is correct
6 Correct 0 ms 512 KB Output is correct
7 Correct 0 ms 520 KB Output is correct
8 Correct 0 ms 512 KB Output is correct
9 Correct 0 ms 520 KB Output is correct
10 Correct 0 ms 520 KB Output is correct
11 Correct 1 ms 564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 72 ms 10356 KB Partially correct
2 Partially correct 72 ms 10748 KB Partially correct
3 Partially correct 70 ms 10692 KB Partially correct
4 Partially correct 71 ms 10656 KB Partially correct
5 Partially correct 69 ms 10648 KB Partially correct
6 Partially correct 70 ms 10700 KB Partially correct
7 Partially correct 73 ms 10636 KB Partially correct
8 Partially correct 71 ms 10728 KB Partially correct
9 Partially correct 71 ms 10708 KB Partially correct
10 Partially correct 70 ms 10764 KB Partially correct
11 Partially correct 72 ms 10700 KB Partially correct
12 Partially correct 68 ms 10700 KB Partially correct
13 Partially correct 77 ms 11500 KB Partially correct
14 Partially correct 79 ms 11576 KB Partially correct
15 Partially correct 71 ms 11076 KB Partially correct
16 Partially correct 66 ms 11012 KB Partially correct
17 Partially correct 74 ms 9764 KB Partially correct
18 Partially correct 78 ms 9960 KB Partially correct
19 Partially correct 77 ms 9724 KB Partially correct
20 Partially correct 71 ms 11436 KB Partially correct
21 Partially correct 69 ms 11508 KB Partially correct
22 Partially correct 79 ms 9884 KB Partially correct
23 Partially correct 66 ms 10944 KB Partially correct
24 Partially correct 67 ms 10984 KB Partially correct
25 Partially correct 77 ms 9788 KB Partially correct
26 Partially correct 80 ms 9848 KB Partially correct
27 Partially correct 77 ms 9852 KB Partially correct
28 Partially correct 79 ms 9824 KB Partially correct
29 Partially correct 77 ms 9880 KB Partially correct
30 Partially correct 77 ms 9832 KB Partially correct
31 Partially correct 79 ms 9852 KB Partially correct
32 Partially correct 74 ms 10832 KB Partially correct
33 Partially correct 69 ms 10772 KB Partially correct