Submission #693192

# Submission time Handle Problem Language Result Execution time Memory
693192 2023-02-02T12:54:38 Z Doncho_Bonboncho medians (balkan11_medians) C++14
100 / 100
29 ms 3464 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

bool used[maxn];
int med[maxn], max_ind, min_ind, n;
vector<int> ans;

int find_max(){
	while(max_ind >= 1 && used[max_ind] == 1)
		max_ind--;

	used[max_ind] = 1;
	return max_ind;
}

int find_min(){
	while(min_ind <= 2 * n - 1 && used[min_ind] == 1)
		min_ind++;

	used[min_ind] = 1;
	return min_ind;
}

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

	ans.pb(med[1]);
	used[med[1]] = 1;

	min_ind = 1;
	max_ind = 2 * n - 1;
	
	for(int i = 2; i <= n; i++){
		if(med[i] == med[i - 1]){
			ans.pb(find_max());
			ans.pb(find_min());
		}

		if(med[i] > med[i - 1]){
			ans.pb(find_max());
			if(used[med[i]])
				ans.pb(find_max());
			else{
				ans.pb(med[i]);
				used[med[i]] = 1;
			}
		}

		if(med[i] < med[i - 1]){
			ans.pb(find_min());
			if(used[med[i]])
				ans.pb(find_min());
			else{
				ans.pb(med[i]);
				used[med[i]] = 1;
			}
		}
	}

	for(int i : ans)
		printf("%d ", i);
	printf("\n");

	return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
medians.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d", med + i);
      |   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 292 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 5 ms 852 KB Output is correct
5 Correct 9 ms 1360 KB Output is correct
6 Correct 17 ms 2408 KB Output is correct
7 Correct 29 ms 3464 KB Output is correct