답안 #480737

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480737 2021-10-18T02:17:01 Z socpite 중앙값 배열 (balkan11_medians) C++14
100 / 100
191 ms 1560 KB
#include<bits/stdc++.h>
using namespace std;

int currmin, currmax, pre, n, tmp;
vector<bool> used;
vector<int> ans;

int getmin(){
    while(used[currmin])currmin++;
    return currmin;
}

int getmax(){
    while(used[currmax])currmax--;
    return currmax;
}

void query(int x){
    cout << x << " ";
    used[x]=true;
}

int main(){
    cin >> n;
    used.assign(2*n, false);
    currmin = 1;
    currmax = 2*n-1;
    cin >> tmp;
    query(tmp);
    pre = tmp;
    for(int i = 0; i < n-1; i++){
        cin >> tmp;
        if(tmp > pre){
            if(!used[tmp])query(tmp);
            else query(getmax());
            query(getmax());
        }
        else if(tmp < pre){
            if(!used[tmp])query(tmp);
            else query(getmin());
            query(getmin());
        }
        else{
            query(getmin());
            query(getmax());
        }
        pre = tmp;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 236 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 204 KB Output is correct
2 Correct 8 ms 332 KB Output is correct
3 Correct 16 ms 344 KB Output is correct
4 Correct 34 ms 392 KB Output is correct
5 Correct 65 ms 640 KB Output is correct
6 Correct 121 ms 988 KB Output is correct
7 Correct 191 ms 1560 KB Output is correct