답안 #715821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715821 2023-03-28T06:56:17 Z Nhoksocqt1 Ancient Machine (JOI21_ancient_machine) C++17
5 / 100
69 ms 10532 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 < 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[pos[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;
        //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];
                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];
                    }
                }

                i = prv[j];
            }
        }
    }

    //cout << "COUNT PAIRS: " << CNT << '\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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 0 ms 524 KB Output is correct
4 Correct 1 ms 516 KB Output is correct
5 Correct 1 ms 524 KB Output is correct
6 Correct 1 ms 524 KB Output is correct
7 Correct 1 ms 516 KB Output is correct
8 Correct 1 ms 516 KB Output is correct
9 Correct 1 ms 516 KB Output is correct
10 Correct 0 ms 624 KB Output is correct
11 Correct 1 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 69 ms 10532 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -