Submission #440171

# Submission time Handle Problem Language Result Execution time Memory
440171 2021-07-01T16:49:40 Z rainboy Mechanical Doll (IOI18_doll) C++11
100 / 100
91 ms 12100 KB
#include "doll.h"
#include <string.h>

using namespace std;

typedef vector<int> vi;

const int N = 200000, M = 100000, L = 17, N_ = 1 << L;	/* L = floor(log2(N))) */

int tmp[N_];

void split(int *aa, int n) {
	int i, j, k;

	for (i = 0, j = n / 2, k = 0; k < n; k++)
		tmp[k % 2 == 0 ? i++ : j++] = aa[k];
	memcpy(aa, tmp, n * sizeof *tmp);
}

vi xx(N * 2), yy(N * 2); int k;

int build(int *aa, int n) {
	if (n == 1)
		return aa[0];
	else {
		int u = k++;

		split(aa, n);
		xx[u] = build(aa, n / 2), yy[u] = build(aa + n / 2, n / 2);
		return -(u + 1);
	}
}

char used[L + 1]; int aaa[L + 1][N + 1], nn[L + 1];

void create_circuit(int m, vi aa) {
	vi cc(m + 1, -1);
	int n = aa.size(), l_, l, i, i_;

	l_ = 1;
	while (1 << l_ + 1 <= n + 1)
		l_++;
	if (1 << l_ == n + 1) {
		for (i = 0; i <= n; i++)
			aaa[0][i] = i == n ? 0 : aa[i];
		build(aaa[0], n + 1);
	} else {
		for (l = 0; l <= l_; l++)
			used[l] = (n + 1 & 1 << l_ - l) != 0;
		for (l = 0; l <= l_; l++)
			yy[l] = l == l_ ? 0 : -(l + 1 + 1);
		for (i_ = 0, i = 0; i_ + 1 < 1 << l_ + 1; i_++) {
			l = 0;
			while (((i_ + 1) & 1 << l) == 0)
				l++;
			if (used[l])
				aaa[l][nn[l]++] = i == n ? -1 : aa[i++];
		}
		k = l_ + 1;
		for (l = 0; l <= l_; l++)
			xx[l] = used[l] ? build(aaa[l], nn[l]) : -1;
	}
	xx.resize(k), yy.resize(k);
	answer(cc, xx, yy);
}

Compilation message

doll.cpp: In function 'void create_circuit(int, vi)':
doll.cpp:41:17: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   41 |  while (1 << l_ + 1 <= n + 1)
      |              ~~~^~~
doll.cpp:49:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   49 |    used[l] = (n + 1 & 1 << l_ - l) != 0;
      |                            ~~~^~~
doll.cpp:49:17: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   49 |    used[l] = (n + 1 & 1 << l_ - l) != 0;
      |               ~~^~~
doll.cpp:52:40: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   52 |   for (i_ = 0, i = 0; i_ + 1 < 1 << l_ + 1; i_++) {
      |                                     ~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 40 ms 6640 KB Output is correct
3 Correct 34 ms 6256 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 12 ms 4556 KB Output is correct
6 Correct 65 ms 7544 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 40 ms 6640 KB Output is correct
3 Correct 34 ms 6256 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 12 ms 4556 KB Output is correct
6 Correct 65 ms 7544 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 60 ms 9156 KB Output is correct
9 Correct 80 ms 9560 KB Output is correct
10 Correct 91 ms 12100 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 40 ms 6640 KB Output is correct
3 Correct 34 ms 6256 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 12 ms 4556 KB Output is correct
6 Correct 65 ms 7544 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 60 ms 9156 KB Output is correct
9 Correct 80 ms 9560 KB Output is correct
10 Correct 91 ms 12100 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 2 ms 3404 KB Output is correct
13 Correct 2 ms 3404 KB Output is correct
14 Correct 88 ms 11688 KB Output is correct
15 Correct 59 ms 8772 KB Output is correct
16 Correct 84 ms 11468 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 2 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 88 ms 11844 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 50 ms 7524 KB Output is correct
3 Correct 53 ms 7532 KB Output is correct
4 Correct 90 ms 9336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 50 ms 7524 KB Output is correct
3 Correct 53 ms 7532 KB Output is correct
4 Correct 90 ms 9336 KB Output is correct
5 Correct 86 ms 9988 KB Output is correct
6 Correct 82 ms 9956 KB Output is correct
7 Correct 81 ms 10148 KB Output is correct
8 Correct 81 ms 9792 KB Output is correct
9 Correct 53 ms 7536 KB Output is correct
10 Correct 82 ms 9660 KB Output is correct
11 Correct 84 ms 9396 KB Output is correct
12 Correct 52 ms 7532 KB Output is correct
13 Correct 54 ms 7736 KB Output is correct
14 Correct 54 ms 7868 KB Output is correct
15 Correct 67 ms 8000 KB Output is correct
16 Correct 3 ms 3532 KB Output is correct
17 Correct 51 ms 7532 KB Output is correct
18 Correct 53 ms 7500 KB Output is correct
19 Correct 52 ms 7544 KB Output is correct
20 Correct 78 ms 9500 KB Output is correct
21 Correct 80 ms 9332 KB Output is correct
22 Correct 78 ms 9464 KB Output is correct