제출 #1333247

#제출 시각아이디문제언어결과실행 시간메모리
1333247herissonwowwStone Arranging 2 (JOI23_ho_t1)C++20
60 / 100
139 ms12388 KiB
#include <bits/stdc++.h>

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;
    }
    map<int,int> lastx;
    int first1 = -1;
    int first2 = -1;
    for(int i = 0; i < n; i++){
        int color; cin >> color;
        lastx[color] = i;
        stones[i] = color;
    }
    for(int i = 0; i < n; i++){
        int color = stones[i];
        for(int j = i; j < lastx[color]; j++){
            stones[j] = color;
        }
        i = lastx[color]+1;
    }
    for(int i = 0; i < n; i++)
        cout << stones[i] << '\n';
    /*
    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...