답안 #761298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761298 2023-06-19T13:23:38 Z BidoTeima 중앙값 배열 (balkan11_medians) C++17
100 / 100
19 ms 3788 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
int main()
{ 
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); 
    int n;
    cin>>n;
    int b[n];
    for(int i = 0; i < n; i++)cin>>b[i];
    vector<int>ans;
    int mn = 1, mx = 2 * n - 1;
    bool used[2 * n]={0};
    used[b[0]] = 1; 
    ans.push_back(b[0]);
    auto addMax = [&](){
        while(used[mx])mx--;
        ans.push_back(mx);
        used[mx]=1;
    };
    auto addMin = [&](){
        while(used[mn])mn++;
        ans.push_back(mn);
        used[mn]=1;
    };
    for(int i = 1; i < n; i++){
        if(b[i] == b[i - 1]){
            addMax();
            addMin();
        }
        else if(b[i] > b[i - 1]){ 
            addMax();
            if(!used[b[i]]){
                ans.push_back(b[i]);
                used[b[i]] = 1;
            }
            else addMax();
        }
        else{
            addMin();
            if(!used[b[i]]){
                ans.push_back(b[i]);
                used[b[i]] = 1;
            }
            else addMin();
        }
    }
    for(int i : ans)cout<<i<<' ';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 284 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 6 ms 1404 KB Output is correct
6 Correct 12 ms 2388 KB Output is correct
7 Correct 19 ms 3788 KB Output is correct