답안 #637883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637883 2022-09-03T13:47:18 Z google 중앙값 배열 (balkan11_medians) C++17
100 / 100
72 ms 12356 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n,l,r,cur,la; cin >> n;
	l = 1,r = n*2-1;
	vector<int> ans;
	set<int> used;
	cin >> cur;
	used.insert(cur);
	ans.push_back(cur);
	for (int i = 0;i<n-1;i++) {
		la = cur; cin >> cur;
		if (used.count(cur)){
			if (cur == la){
				while (used.count(l)) l++;
				used.insert(l);
				ans.push_back(l);
				l++;
				while (used.count(r)) r--;
				used.insert(r);
				ans.push_back(r);
				r--;
			}
			else{
				if (cur > la){
					while (used.count(r)) r--;
					used.insert(r);
					ans.push_back(r);
					r--;
					while (used.count(r)) r--;
					used.insert(r);
					ans.push_back(r);
					r--;
				}
				else{
					while (used.count(l)) l++;
					used.insert(l);
					ans.push_back(l);
					l++;
					while (used.count(l)) l++;
					used.insert(l);
					ans.push_back(l);
					l++;
				}
			}
		}
		else{
			ans.push_back(cur);
			used.insert(cur);
			if (cur > la){
				while (used.count(r)) r--;
				used.insert(r);
				ans.push_back(r);
				r--;
			}
			else{
				while (used.count(l)) l++;
				used.insert(l);
				ans.push_back(l);
				l++;
			}
		}
	}
	for (auto a:ans) cout << a << ' ';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 4 ms 724 KB Output is correct
3 Correct 7 ms 1196 KB Output is correct
4 Correct 12 ms 2252 KB Output is correct
5 Correct 23 ms 4060 KB Output is correct
6 Correct 53 ms 7984 KB Output is correct
7 Correct 72 ms 12356 KB Output is correct