Submission #50219

# Submission time Handle Problem Language Result Execution time Memory
50219 2018-06-08T10:33:21 Z rondojim medians (balkan11_medians) C++17
20 / 100
125 ms 22444 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int A[2 * MAXN], B[MAXN], N, cnt[2 * MAXN];
set<int> S;

int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; ++i){ scanf("%d", &B[i]); cnt[B[i]]++; }
	for(int i=1; i<2*N; ++i) S.insert(i);
	for(int i=1; i<N; ++i){ if(S.find(B[i]) != S.end()) S.erase(S.find(B[i])); }
	A[1] = B[1];
	for(int i=N; i>=2; --i){
		int p = B[i - 1], c = B[i];
		set<int>::iterator it;
		if(c > p){
			for(int j=2*i-1; j>=2*i-2; --j){
				auto it = S.lower_bound(B[i]);
				if(it != S.end()) A[j] = *it;
				if(it != S.end()) S.erase(it);
			}
		}
		else if(c < p){
			for(int j=2*i-1; j>=2*i-2; --j){
				it = S.lower_bound(B[i - 1]);
				if(it != S.end() && *it >= B[i - 1]) --it;
				if(it != S.end()) A[j] = *it;
				if(it != S.end())S.erase(it);
			}
		}
		else{
			it = S.upper_bound(B[i]);
			if(it != S.end()) A[2 * i - 1] = *it;
			if(it != S.end()) S.erase(it);
			it = S.lower_bound(B[i]);
			if(it == S.end()) --it;
			else if(*it >= B[i]) --it;
			A[2 * i - 2] = *it;
			if(it != S.end()) S.erase(it);
		}
		if(cnt[B[i - 1]] == 1) S.insert(B[i - 1]);
		else cnt[B[i - 1]]--;
	}
	for(int i=1; i<2*N; ++i) printf("%d ", A[i]);
	return 0;
}	

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
medians.cpp:12:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; ++i){ scanf("%d", &B[i]); cnt[B[i]]++; }
                           ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Integer 0 violates the range [1, 39]
3 Correct 2 ms 416 KB Output is correct
4 Runtime error 2 ms 620 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Incorrect 2 ms 696 KB Integer 0 violates the range [1, 99]
6 Incorrect 2 ms 744 KB Integer 0 violates the range [1, 119]
7 Runtime error 3 ms 752 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Incorrect 2 ms 872 KB Integer 0 violates the range [1, 159]
9 Incorrect 2 ms 888 KB Integer 0 violates the range [1, 179]
10 Incorrect 2 ms 888 KB Integer 0 violates the range [1, 199]
11 Runtime error 2 ms 892 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Correct 3 ms 984 KB Output is correct
13 Incorrect 2 ms 984 KB Integer 0 violates the range [1, 1999]
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1060 KB Integer 0 violates the range [1, 3999]
2 Correct 5 ms 1332 KB Output is correct
3 Incorrect 9 ms 1844 KB Integer 0 violates the range [1, 15999]
4 Incorrect 18 ms 2868 KB Integer 0 violates the range [1, 31999]
5 Incorrect 35 ms 4788 KB Integer 0 violates the range [1, 63999]
6 Runtime error 70 ms 15004 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 125 ms 22444 KB Execution killed with signal 11 (could be triggered by violating memory limits)