Submission #427081

# Submission time Handle Problem Language Result Execution time Memory
427081 2021-06-14T12:15:37 Z CodePlatina Ancient Machine (JOI21_ancient_machine) C++17
90 / 100
90 ms 9184 KB
#include "Anna.h"
#include <bits/stdc++.h>
#define pii pair<int, int>
#define ff first
#define ss second

using namespace std;

namespace
{

}

void Anna(int N, vector<char> S)
{
    int start = -1, last = -1;
    for(int i = 0; i < N; ++i)
    {
        if(start == -1 && S[i] == 'X') start = i;
        if(S[i] == 'Z') last = i;
    }

    vector<int> R;

    if(start == -1 || last == -1 || start > last)
    {
        Send(0);
        return;
    }

    Send(1);
    for(int i = 0; i < 17; ++i) Send(start >> i & 1);
    for(int i = 0; i < 17; ++i) Send(last >> i & 1);

    for(int i = start + 1; i < last; ++i)
    {
        if(S[i] == 'X' && S[i - 1] == 'Y') R.push_back(1);
        else if(S[i] == 'Y' && S[i + 1] == 'X') R.push_back(1);
        else R.push_back(0);
    }
    for(int i = last + 1; i < N; ++i) R.push_back(0);

    vector<int> Q{0, 0};
    int pt = 0;
    while(pt < (int)R.size())
    {
        if(R[pt] == 0) Q.push_back(0), ++pt;
        else Q.push_back(1), pt += 2;
    }

    vector<int> T{0, 1};
    pt = 0;
    while(pt < (int)R.size())
    {
        if(R[pt] == 0)
        {
            if(pt + 1 < (int)R.size() && R[pt + 1] == 0) T.push_back(0), pt += 2;
            else T.push_back(1), T.push_back(0), pt += 3;
        }
        else T.push_back(1), T.push_back(1), pt += 2;
    }

    if(T.size() < Q.size()) swap(T, Q);
    T = {1, 0};
    pt = 0;
    while(pt < (int)R.size())
    {
        if(R[pt] == 1)
        {
            if(pt + 2 < (int)R.size() && R[pt + 2] == 0) T.push_back(0), pt += 3;
            else T.push_back(1), T.push_back(1), pt += 4;
        }
        else T.push_back(1), T.push_back(0), ++pt;
    }

    if(T.size() < Q.size()) swap(T, Q);
    T = {1, 1};
    pt = 0;
    while(pt < (int)R.size())
    {
        if(R[pt] == 1)
        {
            if(pt + 2 < (int)R.size() && R[pt + 2] == 0) T.push_back(1), T.push_back(0), pt += 3;
            else T.push_back(1), T.push_back(1), pt += 4;
        }
        else T.push_back(0), ++pt;
    }

    if(T.size() < Q.size()) swap(T, Q);

    for(auto i : Q) Send(i);
}
#include "Bruno.h"
#include <bits/stdc++.h>

using namespace std;

namespace
{

}

void Bruno(int N, int L, vector<int> A)
{
    if(A[0] == 0)
    {
        for(int i = 0; i < N; ++i) Remove(i);
        return;
    }

    int start = 0, last = 0;
    for(int i = 0; i < 17; ++i) if(A[i + 1]) start += 1 << i;
    for(int i = 0; i < 17; ++i) if(A[i + 18]) last += 1 << i;

    vector<int> B;
    for(int i = 0; i < start; ++i) B.push_back(0);
    B.push_back(1);

    if(A[35] == 0 && A[36] == 0)
    {
        for(int i = 37; i < (int)A.size(); ++i)
        {
            if(A[i] == 0) B.push_back(0);
            else B.push_back(1), B.push_back(1);
        }
    }
    else if(A[35] == 0 && A[36] == 1)
    {
        for(int i = 37; i < (int)A.size(); i += 2)
        {
            if(A[i] == 0) B.push_back(0), B.push_back(0), --i;
            else if(A[i + 1] == 0) B.push_back(0), B.push_back(1), B.push_back(1);
            else B.push_back(1), B.push_back(1);
        }
    }
    else if(A[35] == 1 && A[36] == 0)
    {
        for(int i = 37; i < (int)A.size(); i += 2)
        {
            if(A[i] == 0) B.push_back(1), B.push_back(1), B.push_back(0), --i;
            else if(A[i + 1] == 0) B.push_back(0);
            else B.push_back(1), B.push_back(1), B.push_back(1), B.push_back(1);
        }
    }
    else
    {
        for(int i = 37; i < (int)A.size(); i += 2)
        {
            if(A[i] == 0) B.push_back(0), --i;
            else if(A[i + 1] == 0) B.push_back(1), B.push_back(1), B.push_back(0);
            else B.push_back(1), B.push_back(1), B.push_back(1), B.push_back(1);
        }
    }

    B.resize(last);
    B.push_back(1);
    for(int i = last + 1; i < N; ++i) B.push_back(0);

    for(int i = 0; i < N; ++i) if(B[i]) last = i;
    for(int i = 0; i < N; ++i) if(!B[i]) Remove(i);
    for(int i = last - 1; i >= 0; --i) if(B[i]) Remove(i);
    Remove(last);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 1 ms 484 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 1 ms 484 KB Output is correct
6 Correct 1 ms 484 KB Output is correct
7 Correct 1 ms 484 KB Output is correct
8 Correct 1 ms 480 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 484 KB Output is correct
11 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 8700 KB Output is correct
2 Correct 73 ms 9036 KB Output is correct
3 Correct 77 ms 9080 KB Output is correct
4 Correct 73 ms 9024 KB Output is correct
5 Correct 90 ms 9012 KB Output is correct
6 Correct 75 ms 9028 KB Output is correct
7 Correct 72 ms 9004 KB Output is correct
8 Correct 67 ms 9024 KB Output is correct
9 Correct 66 ms 9024 KB Output is correct
10 Correct 69 ms 9016 KB Output is correct
11 Correct 66 ms 9044 KB Output is correct
12 Correct 68 ms 9052 KB Output is correct
13 Correct 64 ms 8644 KB Output is correct
14 Correct 66 ms 8964 KB Output is correct
15 Correct 71 ms 8904 KB Output is correct
16 Correct 54 ms 8424 KB Output is correct
17 Correct 57 ms 6776 KB Output is correct
18 Correct 53 ms 6760 KB Output is correct
19 Correct 54 ms 6780 KB Output is correct
20 Partially correct 79 ms 9176 KB Partially correct
21 Partially correct 69 ms 9184 KB Partially correct
22 Correct 73 ms 8928 KB Output is correct
23 Correct 65 ms 8768 KB Output is correct
24 Correct 76 ms 8788 KB Output is correct
25 Correct 61 ms 6792 KB Output is correct
26 Correct 61 ms 6700 KB Output is correct
27 Correct 53 ms 6656 KB Output is correct
28 Correct 54 ms 6756 KB Output is correct
29 Correct 52 ms 6728 KB Output is correct
30 Correct 61 ms 6808 KB Output is correct
31 Correct 61 ms 6716 KB Output is correct
32 Correct 68 ms 9068 KB Output is correct
33 Correct 69 ms 9040 KB Output is correct