답안 #96428

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96428 2019-02-09T12:36:43 Z ics0503 Swap (BOI16_swap) C++17
68 / 100
1000 ms 21368 KB
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[33][221212], n, ck[33][221212],A[33][221212], 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]);
                              ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
16 Correct 32 ms 4988 KB Output is correct
17 Correct 49 ms 4728 KB Output is correct
18 Correct 54 ms 5112 KB Output is correct
19 Correct 549 ms 7372 KB Output is correct
20 Correct 518 ms 7344 KB Output is correct
# 결과 실행 시간 메모리 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 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
16 Correct 32 ms 4988 KB Output is correct
17 Correct 49 ms 4728 KB Output is correct
18 Correct 54 ms 5112 KB Output is correct
19 Correct 549 ms 7372 KB Output is correct
20 Correct 518 ms 7344 KB Output is correct
21 Correct 175 ms 19980 KB Output is correct
22 Correct 156 ms 21240 KB Output is correct
23 Correct 184 ms 21368 KB Output is correct
24 Execution timed out 1085 ms 19536 KB Time limit exceeded
25 Halted 0 ms 0 KB -