답안 #54163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
54163 2018-07-02T14:39:02 Z zadrga 중앙값 배열 (balkan11_medians) C++14
100 / 100
46 ms 4880 KB
// 16.30
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

bool used[maxn];
int med[maxn], max_ind, min_ind, n;
vector<int> ans;

int find_max(){
	while(max_ind >= 1 && used[max_ind] == 1)
		max_ind--;

	used[max_ind] = 1;
	return max_ind;
}

int find_min(){
	while(min_ind <= 2 * n - 1 && used[min_ind] == 1)
		min_ind++;

	used[min_ind] = 1;
	return min_ind;
}

int main(){
	scanf("%d", &n);	
	for(int i = 1; i <= n; i++)
		scanf("%d", med + i);

	ans.pb(med[1]);
	used[med[1]] = 1;

	min_ind = 1;
	max_ind = 2 * n - 1;
	
	for(int i = 2; i <= n; i++){
		if(med[i] == med[i - 1]){
			ans.pb(find_max());
			ans.pb(find_min());
		}

		if(med[i] > med[i - 1]){
			ans.pb(find_max());
			if(used[med[i]])
				ans.pb(find_max());
			else{
				ans.pb(med[i]);
				used[med[i]] = 1;
			}
		}

		if(med[i] < med[i - 1]){
			ans.pb(find_min());
			if(used[med[i]])
				ans.pb(find_min());
			else{
				ans.pb(med[i]);
				used[med[i]] = 1;
			}
		}
	}

	for(int i : ans)
		printf("%d ", i);
	printf("\n");
	
	return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n); 
  ~~~~~^~~~~~~~~~
medians.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", med + i);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 3 ms 532 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 3 ms 740 KB Output is correct
8 Correct 2 ms 740 KB Output is correct
9 Correct 2 ms 740 KB Output is correct
10 Correct 3 ms 740 KB Output is correct
11 Correct 2 ms 740 KB Output is correct
12 Correct 3 ms 740 KB Output is correct
13 Correct 3 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 740 KB Output is correct
2 Correct 4 ms 880 KB Output is correct
3 Correct 8 ms 1088 KB Output is correct
4 Correct 14 ms 1400 KB Output is correct
5 Correct 13 ms 2020 KB Output is correct
6 Correct 25 ms 3228 KB Output is correct
7 Correct 46 ms 4880 KB Output is correct