Submission #1333241

#TimeUsernameProblemLanguageResultExecution timeMemory
1333241herissonwowwStone Arranging 2 (JOI23_ho_t1)C++20
25 / 100
28 ms1440 KiB
#include <iostream>

using namespace std;

int main()
{
    int n; cin >> n;
    int stones[n];
    bool flag = true;
    if(n<=2000){
        for(int i = 0; i < n; i++){
            int color; cin >> color;
            stones[i] = color;
            int lastc = -1;
            for(int j = 0; j < i; j++){
                if(stones[j] == color)
                    lastc = j;
            }
            if(lastc==-1)
                continue;
            for(int j = lastc; j < i; j++){
                stones[j] = color;
            }
        }
        for(int i : stones)
            cout << i << '\n';
        return 0;
    }
    int first1 = -1;
    int first2 = -1;
    for(int i = 0; i < n; i++){
        int color; cin >> color;
        if(color == 1){
            if(first1==-1)
                first1 = i;
        }
        else if (color==2){
            if(first2==-1)
                first2 = i;
        }
        stones[i] = color;
        if(color > 2)
            flag = false;
    }
    if(flag){
        int pr = stones[n-1];
        if(pr==1){
            for(int i = first1; i < n; i++){
                stones[i] = 1;
            }
        }
        else{
            for(int i = first2; i < n; i++){
                stones[i] = 2;
            }
        }
    }
    for(int i = 0; i < n; i++)
            cout << stones[i] << '\n';

//1 3 4 1 2 4 7 3 4 7 2 1
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...