Submission #584342

# Submission time Handle Problem Language Result Execution time Memory
584342 2022-06-27T08:32:34 Z 반딧불(#8375) Ancient Machine (JOI21_ancient_machine) C++17
0 / 100
64 ms 8736 KB
#include "Anna.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

namespace nAnna{
    int n;
    int arr[100005];
    int first0=-1, last2=-1, last1=-1;
    vector<int> stk;

    void Anna(int N, vector<char> _s){
        n = N;
        for(int i=0; i<n; i++) arr[i] = _s[i] - 'X';

        for(int i=0; i<n; i++){
            if(arr[i] == 0){
                first0 = i;
                break;
            }
        }
        if(first0<0) return;

        for(int i=n-1; i>=first0; i--){
            if(arr[i] == 2){
                last2 = i;
                break;
            }
        }
        if(last2<0) return;

        for(int i=last2-1; i>=first0; i--){
            if(arr[i] == 1){
                last1 = i;
                break;
            }
        }
        if(last1<0) return;

        for(int i=0; i<first0; i++) Send(0);
        Send(1);
        for(int i=first0+1; i<=last1; ){
            int nextEven = -1;
            int maxOne = -1;
            int pnt = i;
            while(pnt<=last1){
                if(arr[pnt] == 1) maxOne = pnt;
                else{
                    nextEven = pnt;
                    if(maxOne >= 0) break;
                }
                pnt++;
            }
            if(maxOne == last1){
                for(int j=i; j<maxOne; j++) Send(0);
                Send(1);
                for(int j=maxOne+1; j<last2; j++) Send(0);
                Send(1);
                for(int j=last2+1; j<n; j++) Send(0);
                break;
            }
            for(int j=i; j<maxOne; j++) Send(0);
            Send(1);
            Send(0);
            i=maxOne+2;
        }
    }
}

void Anna(int N, vector<char> S){
    return nAnna::Anna(N, S);
}
#include "Bruno.h"
#include <bits/stdc++.h>

using namespace std;

namespace nBruno{
    int n, k;
    int arr[100002];
    bool removed[100002];
    vector<int> stk;

    int last1;

    void remove(int x){
        #ifdef TEST
        printf("Remove %d\n", x);
        #endif // TEST
        Remove(x);
        removed[x] = 1;
    }

    void Bruno(int _n, int _l, vector<int> _vec){
        n = _n, k = _l;
        if(!k){
            for(int i=0; i<n; i++) Remove(i);
            return;
        }
        for(int i=0; i<k; i++) arr[i] = _vec[i];

        #ifdef TEST
        printf("Message: ");
        for(int i=0; i<k; i++) printf("%d ", _vec[i]);
        puts("");
        #endif

        int oneCnt = count(_vec.begin(), _vec.end(), 1);
        last1 = n-1;
        while(arr[last1] != 1) last1--;
        for(int i=0; i<k; i++){
            if(arr[i]){ /// +�� ���
                oneCnt--;
                if(oneCnt == 1){
                    stk.push_back(i);
                    for(int j=i+1; j<last1; j++) Remove(j);
                    stk.push_back(last1);
                    for(int j=last1+1; j<n; j++) Remove(j);
                    break;
                }
                else stk.push_back(i);
            }
            else{ /// -�� ���
                if(stk.empty() || (int)stk.size() % 2) Remove(i);
                else{
                    Remove(stk.back());
                    stk.pop_back();
                    Remove(i);
                }
            }
        }
        for(int i=(int)stk.size()-2; i>=0; i--){
            Remove(stk[i]);
        }
        Remove(stk.back());
    }
}

void Bruno(int N, int L, vector<int> A){
    nBruno::Bruno(N, L, A);
}

Compilation message

Anna.cpp: In function 'void nAnna::Anna(int, std::vector<char>)':
Anna.cpp:45:17: warning: variable 'nextEven' set but not used [-Wunused-but-set-variable]
   45 |             int nextEven = -1;
      |                 ^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 516 KB Output is correct
2 Incorrect 0 ms 520 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 8736 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -