Submission #35521

# Submission time Handle Problem Language Result Execution time Memory
35521 2017-11-24T00:39:40 Z sinhriv medians (balkan11_medians) C++14
0 / 100
146 ms 14992 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 200010;

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

int d(int x){
	if(x < 0) return abs(x);
	return n + n - x;
}

int getopp(int x){
	return x / abs(x);
}

bool cmp(pair < int, int > x, pair < int, int > y){
	if(getopp(x.first) != getopp(y.first)){
		return getopp(x.first) < getopp(y.first);
	}
	return d(x.first) < d(y.first);
}

int main(){
	if(fopen("1.inp", "r")){
		freopen("1.inp", "r", stdin);
	}

	set < int > used;

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

	a[1] = b[1];
	used.insert(a[1]);

	vector < pair < int, int > > relate;

	for(int i = 2; i <= n; ++i){
		if(b[i] == b[i - 1]){
			relate.emplace_back(b[i - 1], i + i - 1);
			relate.emplace_back(-b[i - 1], i + i - 2);
			continue;
		}

		if(used.count(b[i]) == 0){
			a[i + i - 1] = b[i];
			used.insert(b[i]);
		}
		else if(b[i] > b[i - 1]){
			relate.emplace_back(b[i - 1], i + i - 1);
		}
		else{
			relate.emplace_back(-b[i - 1], i + i - 1);
		}

		if(b[i] > b[i - 1]){
			relate.emplace_back(b[i - 1], i + i - 2);
		}
		else{
			relate.emplace_back(-b[i - 1], i + i - 2);
		}
	}

	set < int > fre;
	for(int i = 1; i < n + n; ++i){
		if(used.count(i) == 0) fre.insert(i);
	}

	sort(relate.begin(), relate.end(), cmp);
	for(auto p : relate){
		if(p.first < 0){
			a[p.second] = *fre.begin();
			fre.erase(fre.begin());
		}
		else{
			a[p.second] = *fre.rbegin();
			fre.erase(a[p.second]);
		}
	}

	for(int i = 1; i < n + n; ++i){
		assert(a[i] == 0);
		printf("%d ", a[i]);
	}

	return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:29:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen("1.inp", "r", stdin);
                               ^
medians.cpp:34:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
medians.cpp:36:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", b + i);
                     ^
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
2 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
3 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
4 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
5 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
6 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
7 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
8 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
9 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
10 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
11 Runtime error 0 ms 3588 KB Execution killed because of forbidden syscall gettid (186)
12 Runtime error 0 ms 3720 KB Execution killed because of forbidden syscall gettid (186)
13 Runtime error 0 ms 3720 KB Execution killed because of forbidden syscall gettid (186)
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 3860 KB Execution killed because of forbidden syscall gettid (186)
2 Runtime error 3 ms 3992 KB Execution killed because of forbidden syscall gettid (186)
3 Runtime error 6 ms 4480 KB Execution killed because of forbidden syscall gettid (186)
4 Runtime error 16 ms 5300 KB Execution killed because of forbidden syscall gettid (186)
5 Runtime error 39 ms 7120 KB Execution killed because of forbidden syscall gettid (186)
6 Runtime error 86 ms 10688 KB Execution killed because of forbidden syscall gettid (186)
7 Runtime error 146 ms 14992 KB Execution killed because of forbidden syscall gettid (186)