Submission #693154

# Submission time Handle Problem Language Result Execution time Memory
693154 2023-02-02T12:23:35 Z Doncho_Bonboncho medians (balkan11_medians) C++14
0 / 100
4 ms 396 KB
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int MAX_N = 1e6;
const int INF = 1e9;
const int mod = 1e9 + 7;

int a[MAX_N];
int nas[MAX_N];

int maxInd;
int minInd;

bool viz[MAX_N];

int n;

void updateMin( ){
	while( minInd < 2*n and viz[minInd] ) minInd ++;
}

void updateMax( ){
	while( maxInd > 0 and viz[maxInd] ) maxInd --;
}
int main () {

	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);

	freopen( "medians.in", "r", stdin );
	freopen( "medians.out", "w", stdout );


	std::cin>>n;
	for( int i=0 ; i<n ; i++ ) std::cin>>a[i];
	
	nas[0] = a[0];
	viz[a[0]] = true;

	maxInd = 2*n;
	minInd = 0;
	viz[0] = true;
	viz[2*n] = true;
	
	for( int i=1 ; i<n ; i++ ){
		if( a[i] == a[i-1] ){
			updateMax();
			nas[i*2 -1] = maxInd;
			viz[maxInd] = true;

			updateMin();
			nas[i*2] = minInd;
			viz[minInd] = true;

		}else{
			if( a[i] > a[i-1] ){
				if( !viz[a[i]] ){
					nas[i*2 -1] = a[i];
					viz[a[i]] = true;
					updateMax();
					nas[i*2] = maxInd;
					viz[maxInd] = true;
	
				}else{
					updateMax();
					nas[i*2 -1] = maxInd;
					viz[maxInd] = true;

					updateMax();
					nas[i*2] = maxInd;
					viz[maxInd] = true;
				}
			}else{

				if( !viz[a[i]] ){
					nas[i*2 -1] = a[i];
					viz[a[i]] = true;

					updateMin();
					a[i*2] = minInd;
					viz[minInd] = true;

				}else{
					updateMin();
					nas[i*2 - 1] = minInd;
					viz[minInd] = true;

					updateMin();
					nas[i*2] = minInd;
					viz[minInd] = true;
				}
			}
		}
	}

	for( int i=0 ; i<2*n-1 ; i++ ) std::cout<<nas[i]<<" ";
	std::cout<<"\n";


	return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:31:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  freopen( "medians.in", "r", stdin );
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
medians.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  freopen( "medians.out", "w", stdout );
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
2 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
3 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
4 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
5 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
6 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
7 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
8 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
9 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
10 Incorrect 3 ms 340 KB Unexpected end of file - int32 expected
11 Incorrect 4 ms 340 KB Unexpected end of file - int32 expected
12 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
13 Incorrect 2 ms 396 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Unexpected end of file - int32 expected
2 Incorrect 3 ms 340 KB Unexpected end of file - int32 expected
3 Incorrect 3 ms 340 KB Unexpected end of file - int32 expected
4 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
5 Incorrect 2 ms 340 KB Unexpected end of file - int32 expected
6 Incorrect 3 ms 340 KB Unexpected end of file - int32 expected
7 Incorrect 3 ms 340 KB Unexpected end of file - int32 expected