답안 #1030547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030547 2024-07-22T06:41:29 Z racsosabe 중앙값 배열 (balkan11_medians) C++14
10 / 100
16 ms 2840 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2 * 100000 + 5;

int n;
int a[N];
int b[N];
bool vis[N];

void solve() {
	a[1] = b[1]; vis[b[1]] = true;
	int L = 1, R = 2 * n - 1;
	for(int i = 2; i <= n; i++) {
		int l = 2 * i - 2;
		int r = 2 * i - 1;
		if(b[i - 1] == b[i]) {
			while(vis[L]) L += 1;
			a[l] = L; vis[L] = true;
			while(vis[R]) R -= 1;
			a[r] = R; vis[R] = true;
		}
		else if(b[i - 1] > b[i]) {
			if(not vis[b[i]]) {
				a[l] = b[i]; vis[b[i]] = true;
				while(vis[L]) L += 1;
				a[r] = L; vis[L] = true;
			}
			else {
				while(vis[L]) L += 1;
				a[l] = L; vis[L] = true;
				while(vis[L]) L += 1;
				a[R] = L; vis[L] = true;
			}
		}
		else {
			if(not vis[b[i]]) {
				a[l] = b[i]; vis[b[i]] = true;
				while(vis[R]) R -= 1;
				a[r] = R; vis[R] = true;
			}
			else {
				while(vis[R]) R -= 1;
				a[l] = R; vis[R] = true;
				while(vis[R]) R -= 1;
				a[r] = R; vis[R] = true;
			}
		}
	}
	for(int i = 1; i <= 2 * n - 1; i++) {
		assert(vis[i]);
	}
}

int main() {
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> b[i];
	solve();
	for(int i = 1; i <= 2 * n - 1; i++) cout << a[i] << " \n"[i == 2 * n - 1];
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Integer 0 violates the range [1, 39]
3 Incorrect 0 ms 360 KB Integer 0 violates the range [1, 59]
4 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 79]
5 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 99]
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 139]
8 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 159]
9 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 179]
10 Incorrect 1 ms 348 KB Integer 0 violates the range [1, 199]
11 Incorrect 1 ms 348 KB Integer 0 violates the range [1, 599]
12 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 1199]
13 Incorrect 0 ms 348 KB Integer 0 violates the range [1, 1999]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Integer 0 violates the range [1, 3999]
2 Incorrect 2 ms 348 KB Integer 0 violates the range [1, 7999]
3 Incorrect 2 ms 600 KB Integer 0 violates the range [1, 15999]
4 Incorrect 3 ms 736 KB Integer 0 violates the range [1, 31999]
5 Incorrect 6 ms 1116 KB Integer 0 violates the range [1, 63999]
6 Incorrect 10 ms 1884 KB Integer 0 violates the range [1, 127999]
7 Incorrect 16 ms 2840 KB Integer 0 violates the range [1, 199999]