Submission #584345

# Submission time Handle Problem Language Result Execution time Memory
584345 2022-06-27T08:36:12 Z 반딧불(#8375) Ancient Machine (JOI21_ancient_machine) C++17
70 / 100
73 ms 9316 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(arr[nextEven] == 2 ? 0 : 1);
            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);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 520 KB Output is correct
2 Correct 0 ms 512 KB Output is correct
3 Correct 1 ms 524 KB Output is correct
4 Correct 1 ms 516 KB Output is correct
5 Correct 1 ms 608 KB Output is correct
6 Correct 1 ms 516 KB Output is correct
7 Correct 1 ms 516 KB Output is correct
8 Correct 0 ms 516 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 516 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 56 ms 8800 KB Partially correct
2 Partially correct 60 ms 8804 KB Partially correct
3 Partially correct 60 ms 9140 KB Partially correct
4 Partially correct 56 ms 9060 KB Partially correct
5 Partially correct 64 ms 9116 KB Partially correct
6 Partially correct 73 ms 9056 KB Partially correct
7 Partially correct 61 ms 9008 KB Partially correct
8 Partially correct 57 ms 9092 KB Partially correct
9 Partially correct 57 ms 9084 KB Partially correct
10 Partially correct 63 ms 9112 KB Partially correct
11 Partially correct 69 ms 9172 KB Partially correct
12 Partially correct 56 ms 9040 KB Partially correct
13 Partially correct 56 ms 9316 KB Partially correct
14 Partially correct 56 ms 8964 KB Partially correct
15 Partially correct 66 ms 9056 KB Partially correct
16 Partially correct 53 ms 9224 KB Partially correct
17 Correct 42 ms 7200 KB Output is correct
18 Correct 41 ms 7088 KB Output is correct
19 Correct 43 ms 7188 KB Output is correct
20 Partially correct 57 ms 9304 KB Partially correct
21 Partially correct 55 ms 9124 KB Partially correct
22 Partially correct 56 ms 9012 KB Partially correct
23 Partially correct 64 ms 9068 KB Partially correct
24 Partially correct 54 ms 9112 KB Partially correct
25 Correct 43 ms 7224 KB Output is correct
26 Correct 41 ms 7184 KB Output is correct
27 Correct 45 ms 7116 KB Output is correct
28 Correct 49 ms 7060 KB Output is correct
29 Correct 45 ms 7052 KB Output is correct
30 Correct 41 ms 7120 KB Output is correct
31 Correct 41 ms 7108 KB Output is correct
32 Partially correct 62 ms 9044 KB Partially correct
33 Partially correct 57 ms 9220 KB Partially correct