Submission #160625

# Submission time Handle Problem Language Result Execution time Memory
160625 2019-10-29T01:09:16 Z luciocf medians (balkan11_medians) C++14
100 / 100
35 ms 2168 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5+10;

int a[maxn];

bool mark[maxn];

void print(int i)
{
	printf(" %d", i);
	mark[i] = 1;
}

int main(void)
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	int l = 1, r = 2*n-1;

	printf("%d", a[1]);
	mark[a[1]] = 1;

	for (int i = 2; i <= n; i++)
	{
		if (a[i] == a[i-1])
		{
			while (mark[l]) l++;
			while (mark[r]) r--;

			print(l); print(r);
		}
		else if (a[i] < a[i-1])
		{
			if (mark[a[i]])
			{
				while (mark[l]) l++;
				print(l);

				while (mark[l]) l++;
				print(l);
			}
			else
			{
				print(a[i]);

				while (mark[l]) l++;
				print(l);
			}
		}
		else
		{
			if (mark[a[i]])
			{
				while (mark[r]) r--;
				print(r);

				while (mark[r]) r--;
				print(r);
			}
			else
			{
				print(a[i]);

				while (mark[r]) r--;
				print(r);
			}
		}
	}

	printf("\n");
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
medians.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 4 ms 508 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 12 ms 888 KB Output is correct
6 Correct 22 ms 1528 KB Output is correct
7 Correct 35 ms 2168 KB Output is correct