답안 #935515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935515 2024-02-29T08:30:39 Z wii Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
52 ms 9012 KB
#include <vector>
using namespace std;

void Anna(int N, std::vector<char> S);
void Send(int a);

void Anna(int N, std::vector<char> S) {
    int cnt[3] = {0};
    for (char x: S) {
        if (x == 'X') ++cnt[0];
        if (x == 'Y') ++cnt[1];
        if (x == 'Z') ++cnt[2];
    }

    vector<char> order;
    if (cnt[0] >= cnt[1] && cnt[0] >= cnt[2]) {
        order.push_back('X');
        order.push_back('Y');
        order.push_back('Z');

        Send(0); Send(0);
    } else if (cnt[1] >= cnt[0] && cnt[1] >= cnt[2]) {
        order.push_back('Y');
        order.push_back('X');
        order.push_back('Z');

        Send(0); Send(1);
    } else {
        order.push_back('Z');
        order.push_back('X');
        order.push_back('Y');

        Send(1); Send(1);
    }

    for (char x: S) {
        if (x == order[0])
            Send(1);
        else
            Send(0);
    }

    for (char x: S) {
        if (x != order[0])
            if (x == order[1])
                Send(0);
            else
                Send(1);
    }
}
#include <deque>

#include <vector>
#include <iostream>
using namespace std;

void Bruno(int N, int L, std::vector<int> A);
void Remove(int d);

// 11 XYZXZYXYXYZ

void Bruno(int N, int L, std::vector<int> A) {
    vector<char> order;
    if (A[0] + A[1] == 0) {
        order.push_back('X');
        order.push_back('Y');
        order.push_back('Z');
    }

    if (A[0] + A[1] == 1) {
        order.push_back('Y');
        order.push_back('X');
        order.push_back('Z');
    }

    if (A[0] + A[1] == 2) {
        order.push_back('Z');
        order.push_back('X');
        order.push_back('Y');
    }

    int ptr = 1;

    vector<char> S(N);
    for (int i = 0; i < N; ++i)
        S[i] = '0';

    for (int i = 0; i < N; ++i) {
        ++ptr;
        if (A[ptr] == 1)
            S[i] = order[0];
    }

    for (int i = 0; i < N; ++i) if (S[i] == '0') {
        ++ptr;
        if (A[ptr] == 1)
            S[i] = order[A[ptr] + 1];
    }

    deque<int> d;
    for (int i = N - 1; i >= 0; --i) {
        if (d.empty()) {
            if (S[i] == 'Z') d.push_back(i); else Remove(i);
        } else {
            if (S[i] == 'Y') {
                if (S[d.front()] == 'Z')
                    d.push_front(i);
                else Remove(i);
            } else if (S[i] == 'X') {
                while (d.size() >= 2) {
                    while (d.size() > 1 && S[d.front() == 'Z']) {
                        Remove(d.front()); d.pop_front();
                    }

                    if (S[d[0]] == 'Y' && S[d[1]] == 'Z') {
                        Remove(d[0]); d.pop_front();
                        if (d.size() > 1) Remove(d[0]), d.pop_front();
                    } else break;
                } Remove(i);
            } else d.push_front(i);
        }
    }

    while (!d.empty()) {
        Remove(d[0]); d.pop_front();
    }
}

Compilation message

Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:44:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   44 |         if (x != order[0])
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 788 KB Output is correct
2 Incorrect 0 ms 792 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 52 ms 8912 KB Partially correct
2 Partially correct 51 ms 9012 KB Partially correct
3 Incorrect 51 ms 8956 KB Wrong Answer [6]
4 Halted 0 ms 0 KB -