답안 #14214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14214 2015-05-05T07:31:35 Z comet 중앙값 배열 (balkan11_medians) C++
100 / 100
179 ms 11668 KB
#include<bits/stdc++.h>
std::set<int> s,s2;
int main(){
	int n,a[100010];
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=2*n-1;i++)s.insert(i);
	std::set<int>::iterator it,t;
	int x,y;
	s2.insert(a[0]);
	s.erase(a[0]);
	printf("%d ",a[0]);
	for(int i=1;i<n;i++){
		it=s2.find(a[i-1]);
		if(*it>a[i]){
			t=s.begin();
			if(s2.find(a[i])==s2.end()){
				s2.insert(a[i]);
				x=*t;
				s2.insert(*t);
				printf("%d %d ",a[i],x);
				s.erase(a[i]);
				s.erase(x);
			}
			else{
				x=*t;
				y=*(++t);
				s2.insert(x);
				s2.insert(y);
				printf("%d %d ",x,y);
				s.erase(x);
				s.erase(y);
			}
		}
		else if(*it<a[i]){
			t=s.end();
			t--;
			if(s2.find(a[i])==s2.end()){
				s2.insert(a[i]);
				x=*t;
				s2.insert(*t);
				printf("%d %d ",a[i],x);
				s.erase(a[i]);
				s.erase(x);
			}
			else{
				x=*t;
				y=*(--t);
				s2.insert(x);
				s2.insert(y);
				printf("%d %d ",x,y);
				s.erase(x);
				s.erase(y);
			}
		}
		else{
			t=s.begin();
			x=*t;
			t=s.end();
			t--;
			y=*t;
			s2.insert(x);
			s2.insert(y);
			printf("%d %d ",x,y);
			s.erase(x);
			s.erase(y);
		}
	}
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:5:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
medians.cpp:6:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++)scanf("%d",&a[i]);
                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2288 KB Output is correct
2 Correct 0 ms 2292 KB Output is correct
3 Correct 0 ms 2292 KB Output is correct
4 Correct 0 ms 2292 KB Output is correct
5 Correct 0 ms 2292 KB Output is correct
6 Correct 0 ms 2292 KB Output is correct
7 Correct 0 ms 2292 KB Output is correct
8 Correct 0 ms 2288 KB Output is correct
9 Correct 0 ms 2292 KB Output is correct
10 Correct 0 ms 2292 KB Output is correct
11 Correct 0 ms 2292 KB Output is correct
12 Correct 0 ms 2428 KB Output is correct
13 Correct 0 ms 2424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2552 KB Output is correct
2 Correct 3 ms 2688 KB Output is correct
3 Correct 9 ms 3084 KB Output is correct
4 Correct 19 ms 3748 KB Output is correct
5 Correct 49 ms 5328 KB Output is correct
6 Correct 106 ms 8368 KB Output is correct
7 Correct 179 ms 11668 KB Output is correct