Submission #96427

# Submission time Handle Problem Language Result Execution time Memory
96427 2019-02-09T12:36:10 Z ics0503 Swap (BOI16_swap) C++17
68 / 100
527 ms 14372 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[33][121212], n, ck[33][121212],A[33][121212], ADN[33];
void mkA(int dep, int w) {
	if (n < w)return;
	A[dep][ADN[dep]++] = w;
	ck[dep][w] = 0;
	a[dep][w] = a[dep - 1][w];
	mkA(dep, w * 2); mkA(dep, w * 2 + 1);
}
void mkck(int dep, int w) {
	if (n < w)return;
	ck[dep][w] = 1;
	mkck(dep, w * 2); mkck(dep, w * 2 + 1);
}
void cpy(int dep, int w) {
	if (n < w)return;
	a[dep][w] = a[dep + 1][w];
	cpy(dep, w * 2); cpy(dep, w * 2 + 1);
}
int go(int dep, int G, int w) {
	ADN[dep] = 0; mkA(dep, w);
	a[dep][w] = G;
	for (int x = 0; x < ADN[dep]; x++) {
		int now = A[dep][x];
		if (ck[dep][now])continue;
		int l = now * 2, r = now * 2 + 1;
		if (l > n)continue;
		if (r > n){
			if(a[dep][now] > a[dep][l]) swap(a[dep][now], a[dep][l]);
			continue;
		}
		if (a[dep][now] < a[dep][l] && a[dep][now] < a[dep][r])continue;
		else if (a[dep][l] < a[dep][r] && a[dep][l] < a[dep][now])swap(a[dep][now], a[dep][l]);
		else {
			int mn = min(a[dep][l], a[dep][now]);
			int mx = max(a[dep][l], a[dep][now]);
			a[dep][now] = a[dep][r];
			mkck(dep, now);
			int L = go(dep + 1, mn, now * 2), R = go(dep + 1, mn, now * 2 + 1), p, q;
			if (L < R) p = now * 2, q = now * 2 + 1;
			else p = now * 2 + 1, q = now * 2;
			cpy(dep, p);
			go(dep + 1, mx, q); cpy(dep, q);
		}
	}
	for (int x = 0; x < ADN[dep]; x++)if (a[dep][A[dep][x]] == G)return A[dep][x];
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &a[0][i]);
	go(1, a[0][1], 1);
	for (int i = 1; i <= n; i++) printf("%d ", a[1][i]);
	return 0;
}

Compilation message

swap.cpp: In function 'int go(int, int, int)':
swap.cpp:49:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
swap.cpp: In function 'int main()':
swap.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
swap.cpp:52:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++)scanf("%d", &a[0][i]);
                              ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 31 ms 5240 KB Output is correct
17 Correct 27 ms 4984 KB Output is correct
18 Correct 30 ms 5240 KB Output is correct
19 Correct 512 ms 7468 KB Output is correct
20 Correct 527 ms 7476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 5 ms 504 KB Output is correct
16 Correct 31 ms 5240 KB Output is correct
17 Correct 27 ms 4984 KB Output is correct
18 Correct 30 ms 5240 KB Output is correct
19 Correct 512 ms 7468 KB Output is correct
20 Correct 527 ms 7476 KB Output is correct
21 Incorrect 161 ms 14372 KB Output isn't correct
22 Halted 0 ms 0 KB -