답안 #756894

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756894 2023-06-12T11:07:42 Z KN200711 중앙값 배열 (balkan11_medians) C++14
100 / 100
43 ms 4292 KB
# include <bits/stdc++.h>
using namespace std;

int ct[200001];
int mn, mx, N;

void upd() {
	while(ct[mn] && mn <= N) mn++;
	while(ct[mx] && mx > 0) mx--;
}

int main() {
	scanf("%d", &N);
	vector<int> arr(N);
	for(int i=0;i<N;i++) scanf("%d", &arr[i]);
	vector<int> as;
	as.clear();
	mn = 1;
	mx = 2 * N - 1;
	for(int i=0;i<N;i++) {
		if(i == 0) {
			as.push_back(arr[i]);
			ct[arr[i]]++;
		}
		else {
			upd();
			if(ct[arr[i]]) {
				if(arr[i] > arr[i - 1]) {
					as.push_back(mx);
					ct[mx] = 1;
					upd();
					as.push_back(mx);
				} else if(arr[i] < arr[i - 1]) {
					as.push_back(mn);
					ct[mn] = 1;
					upd();
					as.push_back(mn);
				} else {
					as.push_back(mn);
					as.push_back(mx);
				}
			} else {
				if(arr[i] > arr[i - 1]) {
					as.push_back(arr[i]);
					as.push_back(mx);
				} else if(arr[i] < arr[i - 1]) {
					as.push_back(arr[i]);
					as.push_back(mn);
				} else {
					as.push_back(mn);
					as.push_back(mx);
				}
			}
			ct[as.back()] = 1;
			ct[as[as.size() - 2]] = 1;
		}
	}
	for(int p=0;p<as.size();p++) printf("%d ", as[p]);
	printf("\n");
	return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:58:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int p=0;p<as.size();p++) printf("%d ", as[p]);
      |              ~^~~~~~~~~~
medians.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
medians.cpp:15:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  for(int i=0;i<N;i++) scanf("%d", &arr[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 312 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 9 ms 980 KB Output is correct
5 Correct 11 ms 1552 KB Output is correct
6 Correct 22 ms 2820 KB Output is correct
7 Correct 43 ms 4292 KB Output is correct