Submission #60491

# Submission time Handle Problem Language Result Execution time Memory
60491 2018-07-24T09:07:19 Z junodeveloper medians (balkan11_medians) C++17
100 / 100
65 ms 3244 KB
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
int n, b[100010], a[200010], c1,c2;
bool chk[200010];
int getc1() { while(c1 <=2*n-1 && chk[c1]) c1++; return c1; }
int getc2() { while(c2 && chk[c2]) c2--; return c2; }
int main() {
	scanf("%d", &n);
	c1 = 1, c2 = 2*n-1;
	for(int i=1; i<=n; i++) {
		scanf("%d", b+i);
		if(i == 1) {
			chk[a[1] = b[i]] = 1;
			continue;
		}
		if(b[i-1] > b[i]) {
			if(!chk[b[i]]) chk[a[2*(i-1)] = b[i]] = chk[a[2*(i-1)+1] = getc1()] = 1;
			else chk[a[2*(i-1)] = getc1()] = chk[a[2*(i-1)+1] = getc1()] = 1;
		} else if(b[i-1] < b[i]) {
			if(!chk[b[i]]) chk[a[2*(i-1)] = b[i]] = chk[a[2*(i-1)+1] = getc2()] = 1;
			else chk[a[2*(i-1)] = getc2()] = chk[a[2*(i-1)+1] = getc2()] = 1;
		} else chk[a[2*(i-1)] = getc1()] = chk[a[2*(i-1)+1] = getc2()] = 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:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
medians.cpp:13:8: 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 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 3 ms 624 KB Output is correct
11 Correct 3 ms 624 KB Output is correct
12 Correct 3 ms 624 KB Output is correct
13 Correct 3 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 3 ms 636 KB Output is correct
3 Correct 6 ms 784 KB Output is correct
4 Correct 12 ms 1052 KB Output is correct
5 Correct 18 ms 1452 KB Output is correct
6 Correct 29 ms 2220 KB Output is correct
7 Correct 65 ms 3244 KB Output is correct