답안 #50232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
50232 2018-06-08T11:34:59 Z rondojim 중앙값 배열 (balkan11_medians) C++17
5 / 100
148 ms 22492 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 1e5 + 5;
 
int A[2 * MAXN], B[MAXN], N, cnt[2 * MAXN];
set<int> S;
 
int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; ++i){ scanf("%d", &B[i]); cnt[B[i]]++; }
	for(int i=1; i<2*N; ++i) S.insert(i);
	A[1] = B[1], cnt[B[1]]--;
	S.erase(S.find(B[1]));
	for(int i=2; i<=N; ++i){
		int p = B[i - 1], c = B[i];
		set<int>::iterator it;
		if(c > p){
			for(int j=2*i-1; j>=2*i-2; --j){
				auto it = S.lower_bound(B[i]);
				A[j] = *it;
				S.erase(it);
			}
		}
		else if(c < p){
			for(int j=2*i-1; j>=2*i-2; --j){
				it = S.lower_bound(B[i]);
				if(it == S.end()) --it;
				else if(*it > B[i]) --it;
				A[j] = *it;
				S.erase(it);
			}
		}
		else{
			it = S.upper_bound(B[i]);
			A[2 * i - 1] = *it;
			S.erase(it);
			it = S.lower_bound(B[i]);
			if(it == S.end()) --it;
			else if(*it > B[i]) --it;
			A[2 * i - 2] = *it;
			S.erase(it);
		}
	}
	for(int i=1; i<2*N; ++i) printf("%d ", A[i]);
	return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
medians.cpp:12:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; ++i){ scanf("%d", &B[i]); cnt[B[i]]++; }
                           ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 6 ms 920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 6 ms 920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 6 ms 920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 6 ms 956 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Correct 3 ms 956 KB Output is correct
7 Runtime error 5 ms 1064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 7 ms 1064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 5 ms 1076 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 5 ms 1080 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 5 ms 1212 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 5 ms 1212 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1484 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 8 ms 1916 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 12 ms 2764 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 18 ms 4556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 49 ms 7884 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 72 ms 15180 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 148 ms 22492 KB Execution killed with signal 11 (could be triggered by violating memory limits)