Submission #480721

# Submission time Handle Problem Language Result Execution time Memory
480721 2021-10-18T00:57:26 Z hollwo_pelw medians (balkan11_medians) C++17
5 / 100
32 ms 4072 KB
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>

using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;

void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
	if (fopen(filein.c_str(), "r")){
		freopen(filein.c_str(), "r", stdin);
		freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
		freopen(fileerr.c_str(), "w", stderr);
#endif
	}
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}

void Hollwo_Pelw();

signed main(){
#ifdef hollwo_pelw_local
	FAST_IO("input.inp", "output.out", "error.err");
	auto start = chrono::steady_clock::now();
#else
	FAST_IO("balkan11_medians.inp", "balkan11_medians.out");
#endif
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = chrono::steady_clock::now();
	cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
	return 0;
}

const int N = 1e5 + 5;

int n, b[N], a[N << 1], vis[N << 1];

void Hollwo_Pelw() {
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> b[i];
	int l = 1, r = 2 * n - 1;
	auto assign = [&](int i, int v) { vis[a[i] = v] = 1; };
	auto get_max = [&]() -> int { while (vis[r]) r --; return r; };
	auto get_min = [&]() -> int { while (vis[l]) l ++; return l; };

	assign(1, b[1]);
	for (int i = 2, p = 1; i <= n; i ++) {
		if (b[i] == b[i - 1]) {
			assign(++ p, get_max());
			assign(++ p, get_min());
		}
		if (b[i] > b[i - 1]) {
			assign(++ p, b[i]);
			assign(++ p, get_max());
		}
		if (b[i] < b[i - 1]) {
			assign(++ p, b[i]);
			assign(++ p, get_min());
		}
		// cout << l << ' ' << r << '\n';
	}
	for (int i = 1; i < 2 * n; i++)
		cout << a[i] << ' ';
}

Compilation message

medians.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
medians.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
medians.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Not a permutation
2 Incorrect 0 ms 332 KB Not a permutation
3 Incorrect 0 ms 252 KB Not a permutation
4 Incorrect 1 ms 332 KB Not a permutation
5 Incorrect 0 ms 332 KB Not a permutation
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 0 ms 332 KB Not a permutation
8 Incorrect 1 ms 332 KB Not a permutation
9 Incorrect 0 ms 332 KB Not a permutation
10 Incorrect 0 ms 332 KB Not a permutation
11 Incorrect 1 ms 332 KB Not a permutation
12 Incorrect 1 ms 332 KB Not a permutation
13 Incorrect 1 ms 332 KB Not a permutation
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Not a permutation
2 Incorrect 2 ms 460 KB Not a permutation
3 Incorrect 3 ms 588 KB Not a permutation
4 Incorrect 5 ms 844 KB Not a permutation
5 Incorrect 9 ms 1448 KB Not a permutation
6 Incorrect 18 ms 2596 KB Not a permutation
7 Incorrect 32 ms 4072 KB Not a permutation