Submission #587200

# Submission time Handle Problem Language Result Execution time Memory
587200 2022-07-01T13:27:35 Z M_W Swap (BOI16_swap) C++17
0 / 100
1 ms 316 KB
#include <bits/stdc++.h>
#define ar array<int, 3>
using namespace std;
int a[200002];

ar find_min(int a, int b, int c){
	vector<ar> tmp;
	tmp.push_back({a, b, c});
	tmp.push_back({b, a, c});
	tmp.push_back({c, a, b});
	tmp.push_back({c, b, a});
	sort(tmp.begin(), tmp.end());
	return tmp[0];
}

int main(){
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
	a[N + 1] = INT_MAX;
	for(int i = 1; i * 2 <= N; i++){
		ar tmp;
		if(i * 2 + 1 > N) tmp = find_min(a[i], a[i * 2], max(a[i], a[i * 2]));
		else tmp = find_min(a[i], a[i * 2], a[i * 2 + 1]);
		
		int nxt1 = min(a[min(N + 1, (i * 2) * 2)], a[min(N + 1, (i * 2) * 2 + 1)]);
		int nxt2 = min(a[min(N + 1, (i * 2 + 1) * 2)], a[min(N + 1, (i * 2 + 1) * 2 + 1)]);
		
		if(tmp[0] == a[i * 2 + 1]){
			if(nxt1 < tmp[1] && nxt2 >= tmp[1]) swap(tmp[1], tmp[2]);
		}
		a[i] = tmp[0]; a[i * 2] = tmp[1]; a[i * 2 + 1] = tmp[2];
	}
	for(int i = 1; i <= N; i++) printf("%d ", a[i]);
}

Compilation message

swap.cpp: In function 'int main()':
swap.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
swap.cpp:19:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  for(int i = 1; i <= N; i++) scanf("%d", &a[i]);
      |                              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -