Submission #210769

# Submission time Handle Problem Language Result Execution time Memory
210769 2020-03-18T10:29:04 Z Yojahuang medians (balkan11_medians) C++14
100 / 100
107 ms 11048 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int n;
set<int> G;

void addmin() {
	int v = *G.begin();
	cout << v << ' ';
	G.erase(G.find(v));
}

void addmax() {
	int v = *(--G.end());
	cout << v << ' ';
	G.erase(G.find(v));
}

int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int pre, v;
	while (cin >> n) {
		G.clear();
		for (int i = 1; i <= 2 * n - 1; ++i) {
			G.insert(i);
		}
		cin >> v;
		cout << v << ' ';
		pre = v;
		G.erase(G.find(pre));

		for (int i = 1; i < n; ++i) {
			cin >> v;
			if (v > pre) {
				if (G.find(v)  == G.end()) {
					addmax();
				}else {
					G.erase(G.find(v));
					cout << v << ' ';
				}
				addmax();
			}else if(v == pre) {
				addmin();
				addmax();
			}else if(v < pre) {
				if (G.find(v)  == G.end()) {
					addmin();
				}else {
					G.erase(G.find(v));
					cout << v << ' ';
				}
				addmin();
			}
			pre = v;
		}
		cout << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 296 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 8 ms 760 KB Output is correct
3 Correct 10 ms 1144 KB Output is correct
4 Correct 18 ms 2040 KB Output is correct
5 Correct 33 ms 3704 KB Output is correct
6 Correct 68 ms 7160 KB Output is correct
7 Correct 107 ms 11048 KB Output is correct