답안 #161704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161704 2019-11-03T19:19:06 Z Anai 중앙값 배열 (balkan11_medians) C++14
10 / 100
40 ms 11384 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;

int f[N];

vector<int> v, ant;
set<int> s;
int n, m;


int main() {
#ifdef HOME
	freopen("medians.in", "r", stdin);
	freopen("medians.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int lst;

	cin >> n;
	v.resize(n);
	for (auto &i: v) {
		cin >> i;
		f[i]+= 1; }
	m = 2 * n - 1;

	for (int i = 1; i <= m; ++i)
		if (!f[i])
			s.insert(i);

	lst = v.back();
	if (!--f[lst])
		s.insert(lst);

	for (int i = n - 2; i >= 0; --i) {
		if (v[i] == lst) {
			auto l = prev(s.lower_bound(lst));
			auto r = s.lower_bound(lst);
			ant.push_back(*l), ant.push_back(*r);
			s.erase(l);
			s.erase(r);
		}
		else if (v[i] > lst) {
			auto l = prev(s.upper_bound(lst));
			auto r = prev(l);
			ant.push_back(*l), ant.push_back(*r);
			s.erase(l);
			s.erase(r); }
		else {
			auto l = prev(s.upper_bound(lst));
			auto r = s.upper_bound(lst);
			ant.push_back(*l), ant.push_back(*r);
			s.erase(l);
			s.erase(r); }
		lst = v[i];
		if (--f[v[i]] == 0)
			s.insert(v[i]); }

	ant.push_back(*begin(s));

	reverse(begin(ant), end(ant));
	for (auto i: ant)
		cout << i << ' ';
	cout << endl;

	return 0; }
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Correct 2 ms 376 KB Output is correct
4 Runtime error 5 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Correct 2 ms 376 KB Output is correct
7 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 5 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 4 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 5 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 5 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 7 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 10 ms 2296 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 17 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 31 ms 7032 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 40 ms 11384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 3 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)