Submission #592772

# Submission time Handle Problem Language Result Execution time Memory
592772 2022-07-09T15:03:22 Z rainboy Boarding Passes (BOI22_passes) C
100 / 100
102 ms 23420 KB
#include <stdio.h>
#include <string.h>

#define N	100000
#define A	15

long long min(long long a, long long b) { return a < b ? a : b; }

int main() {
	static char cc[N + 1];
	static int ii[A][N], kk[N], ll[A][N];
	static long long dp[A][A][N + 1], dq[A][1 << A], dr[1 << A];
	int n, h, i, a, a_, b, lower, upper;
	long long x;

	scanf("%s", cc), n = strlen(cc);
	for (i = 0; i < n; i++) {
		a = cc[i] - 'A';
		for (a_ = 0; a_ < A; a_++)
			ll[a_][i] = kk[a_];
		ii[a][kk[a]++] = i;
	}
	for (a = 0; a < A; a++)
		for (a_ = 0; a_ < A; a_++) {
			for (h = 0; h < kk[a]; h++) {
				i = ii[a][h];
				dp[a][a_][0] += kk[a_] - ll[a_][i];
			}
			for (h = 0; h < kk[a]; h++) {
				i = ii[a][h];
				dp[a][a_][h + 1] = dp[a][a_][h] + ll[a_][i] * 2 - kk[a_];
			}
		}
	for (b = 0; b < 1 << A; b++)
		for (a = 0; a < A; a++)
			if ((b & 1 << a) == 0) {
				lower = -1, upper = kk[a];
				while (upper - lower > 1) {
					h = (lower + upper) / 2;
					i = ii[a][h];
					x = h - (kk[a] - 1 - h);
					for (a_ = 0; a_ < A; a_++)
						if ((b & 1 << a_) != 0)
							x += (dp[a][a_][h + 1] - dp[a][a_][h]) * 2;
					if (x > 0)
						upper = h;
					else
						lower = h;
				}
				h = upper;
				dq[a][b] = (long long) h * (h - 1) / 2 + (long long) (kk[a] - h) * (kk[a] - h - 1) / 2;
				for (a_ = 0; a_ < A; a_++)
					if ((b & 1 << a_) != 0)
						dq[a][b] += dp[a][a_][h] * 2;
			}
	memset(dr, 0x3f, (1 << A) * sizeof *dr);
	dr[0] = 0;
	for (b = 0; b < 1 << A; b++)
		for (a = 0; a < A; a++)
			if ((b & 1 << a) == 0)
				dr[b | 1 << a] = min(dr[b | 1 << a], dr[b] + dq[a][b]);
	if (dr[(1 << A) - 1] % 2 == 0)
		printf("%lld\n", dr[(1 << A) - 1] / 2);
	else
		printf("%lld.%lld\n", dr[(1 << A) - 1] / 2, dr[(1 << A) - 1] % 2 * 5);
	return 0;
}

Compilation message

passes.c: In function 'main':
passes.c:16:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |  scanf("%s", cc), n = strlen(cc);
      |  ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4436 KB Output is correct
2 Correct 17 ms 4332 KB Output is correct
3 Correct 18 ms 4456 KB Output is correct
4 Correct 18 ms 4260 KB Output is correct
5 Correct 20 ms 4416 KB Output is correct
6 Correct 34 ms 18632 KB Output is correct
7 Correct 33 ms 21356 KB Output is correct
8 Correct 35 ms 22348 KB Output is correct
9 Correct 35 ms 22284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4416 KB Output is correct
2 Correct 19 ms 4280 KB Output is correct
3 Correct 29 ms 4732 KB Output is correct
4 Correct 29 ms 4748 KB Output is correct
5 Correct 25 ms 4684 KB Output is correct
6 Correct 26 ms 4688 KB Output is correct
7 Correct 31 ms 4728 KB Output is correct
8 Correct 25 ms 4684 KB Output is correct
9 Correct 28 ms 4740 KB Output is correct
10 Correct 30 ms 4688 KB Output is correct
11 Correct 29 ms 4832 KB Output is correct
12 Correct 33 ms 4656 KB Output is correct
13 Correct 27 ms 4640 KB Output is correct
14 Correct 26 ms 4672 KB Output is correct
15 Correct 26 ms 4680 KB Output is correct
16 Correct 26 ms 4684 KB Output is correct
17 Correct 27 ms 4640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 4416 KB Output is correct
2 Correct 19 ms 4280 KB Output is correct
3 Correct 29 ms 4732 KB Output is correct
4 Correct 29 ms 4748 KB Output is correct
5 Correct 25 ms 4684 KB Output is correct
6 Correct 26 ms 4688 KB Output is correct
7 Correct 31 ms 4728 KB Output is correct
8 Correct 25 ms 4684 KB Output is correct
9 Correct 28 ms 4740 KB Output is correct
10 Correct 30 ms 4688 KB Output is correct
11 Correct 29 ms 4832 KB Output is correct
12 Correct 33 ms 4656 KB Output is correct
13 Correct 27 ms 4640 KB Output is correct
14 Correct 26 ms 4672 KB Output is correct
15 Correct 26 ms 4680 KB Output is correct
16 Correct 26 ms 4684 KB Output is correct
17 Correct 27 ms 4640 KB Output is correct
18 Correct 20 ms 4436 KB Output is correct
19 Correct 20 ms 4316 KB Output is correct
20 Correct 35 ms 4688 KB Output is correct
21 Correct 35 ms 4744 KB Output is correct
22 Correct 26 ms 4664 KB Output is correct
23 Correct 22 ms 4736 KB Output is correct
24 Correct 29 ms 4684 KB Output is correct
25 Correct 26 ms 4660 KB Output is correct
26 Correct 27 ms 4744 KB Output is correct
27 Correct 27 ms 4744 KB Output is correct
28 Correct 28 ms 4664 KB Output is correct
29 Correct 28 ms 4696 KB Output is correct
30 Correct 28 ms 4684 KB Output is correct
31 Correct 27 ms 4744 KB Output is correct
32 Correct 26 ms 4660 KB Output is correct
33 Correct 27 ms 4732 KB Output is correct
34 Correct 27 ms 4652 KB Output is correct
35 Correct 22 ms 6068 KB Output is correct
36 Correct 28 ms 6156 KB Output is correct
37 Correct 53 ms 6648 KB Output is correct
38 Correct 51 ms 6712 KB Output is correct
39 Correct 28 ms 6740 KB Output is correct
40 Correct 47 ms 6736 KB Output is correct
41 Correct 49 ms 6660 KB Output is correct
42 Correct 50 ms 6680 KB Output is correct
43 Correct 49 ms 6684 KB Output is correct
44 Correct 49 ms 6600 KB Output is correct
45 Correct 49 ms 6592 KB Output is correct
46 Correct 50 ms 6576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 4436 KB Output is correct
2 Correct 17 ms 4332 KB Output is correct
3 Correct 18 ms 4456 KB Output is correct
4 Correct 18 ms 4260 KB Output is correct
5 Correct 20 ms 4416 KB Output is correct
6 Correct 34 ms 18632 KB Output is correct
7 Correct 33 ms 21356 KB Output is correct
8 Correct 35 ms 22348 KB Output is correct
9 Correct 35 ms 22284 KB Output is correct
10 Correct 23 ms 4416 KB Output is correct
11 Correct 19 ms 4280 KB Output is correct
12 Correct 29 ms 4732 KB Output is correct
13 Correct 29 ms 4748 KB Output is correct
14 Correct 25 ms 4684 KB Output is correct
15 Correct 26 ms 4688 KB Output is correct
16 Correct 31 ms 4728 KB Output is correct
17 Correct 25 ms 4684 KB Output is correct
18 Correct 28 ms 4740 KB Output is correct
19 Correct 30 ms 4688 KB Output is correct
20 Correct 29 ms 4832 KB Output is correct
21 Correct 33 ms 4656 KB Output is correct
22 Correct 27 ms 4640 KB Output is correct
23 Correct 26 ms 4672 KB Output is correct
24 Correct 26 ms 4680 KB Output is correct
25 Correct 26 ms 4684 KB Output is correct
26 Correct 27 ms 4640 KB Output is correct
27 Correct 20 ms 4436 KB Output is correct
28 Correct 20 ms 4316 KB Output is correct
29 Correct 35 ms 4688 KB Output is correct
30 Correct 35 ms 4744 KB Output is correct
31 Correct 26 ms 4664 KB Output is correct
32 Correct 22 ms 4736 KB Output is correct
33 Correct 29 ms 4684 KB Output is correct
34 Correct 26 ms 4660 KB Output is correct
35 Correct 27 ms 4744 KB Output is correct
36 Correct 27 ms 4744 KB Output is correct
37 Correct 28 ms 4664 KB Output is correct
38 Correct 28 ms 4696 KB Output is correct
39 Correct 28 ms 4684 KB Output is correct
40 Correct 27 ms 4744 KB Output is correct
41 Correct 26 ms 4660 KB Output is correct
42 Correct 27 ms 4732 KB Output is correct
43 Correct 27 ms 4652 KB Output is correct
44 Correct 22 ms 6068 KB Output is correct
45 Correct 28 ms 6156 KB Output is correct
46 Correct 53 ms 6648 KB Output is correct
47 Correct 51 ms 6712 KB Output is correct
48 Correct 28 ms 6740 KB Output is correct
49 Correct 47 ms 6736 KB Output is correct
50 Correct 49 ms 6660 KB Output is correct
51 Correct 50 ms 6680 KB Output is correct
52 Correct 49 ms 6684 KB Output is correct
53 Correct 49 ms 6600 KB Output is correct
54 Correct 49 ms 6592 KB Output is correct
55 Correct 50 ms 6576 KB Output is correct
56 Correct 22 ms 4564 KB Output is correct
57 Correct 30 ms 5148 KB Output is correct
58 Correct 20 ms 4512 KB Output is correct
59 Correct 18 ms 4264 KB Output is correct
60 Correct 18 ms 4288 KB Output is correct
61 Correct 17 ms 4328 KB Output is correct
62 Correct 20 ms 4436 KB Output is correct
63 Correct 30 ms 18556 KB Output is correct
64 Correct 34 ms 21324 KB Output is correct
65 Correct 38 ms 22380 KB Output is correct
66 Correct 42 ms 22348 KB Output is correct
67 Correct 19 ms 4436 KB Output is correct
68 Correct 21 ms 4344 KB Output is correct
69 Correct 29 ms 4692 KB Output is correct
70 Correct 30 ms 4712 KB Output is correct
71 Correct 27 ms 4704 KB Output is correct
72 Correct 21 ms 4672 KB Output is correct
73 Correct 37 ms 4684 KB Output is correct
74 Correct 27 ms 4616 KB Output is correct
75 Correct 28 ms 4696 KB Output is correct
76 Correct 29 ms 4744 KB Output is correct
77 Correct 27 ms 4684 KB Output is correct
78 Correct 26 ms 4736 KB Output is correct
79 Correct 29 ms 4768 KB Output is correct
80 Correct 28 ms 4692 KB Output is correct
81 Correct 27 ms 4748 KB Output is correct
82 Correct 27 ms 4656 KB Output is correct
83 Correct 27 ms 4692 KB Output is correct
84 Correct 23 ms 6052 KB Output is correct
85 Correct 24 ms 6088 KB Output is correct
86 Correct 53 ms 6648 KB Output is correct
87 Correct 49 ms 6628 KB Output is correct
88 Correct 31 ms 6756 KB Output is correct
89 Correct 56 ms 6740 KB Output is correct
90 Correct 56 ms 6644 KB Output is correct
91 Correct 50 ms 6676 KB Output is correct
92 Correct 51 ms 6568 KB Output is correct
93 Correct 50 ms 6604 KB Output is correct
94 Correct 49 ms 6704 KB Output is correct
95 Correct 52 ms 6720 KB Output is correct
96 Correct 96 ms 23420 KB Output is correct
97 Correct 31 ms 5076 KB Output is correct
98 Correct 91 ms 23244 KB Output is correct
99 Correct 39 ms 23184 KB Output is correct
100 Correct 25 ms 5268 KB Output is correct
101 Correct 83 ms 23360 KB Output is correct
102 Correct 89 ms 23308 KB Output is correct
103 Correct 92 ms 23108 KB Output is correct
104 Correct 96 ms 23272 KB Output is correct
105 Correct 87 ms 23180 KB Output is correct
106 Correct 90 ms 23212 KB Output is correct
107 Correct 91 ms 23164 KB Output is correct
108 Correct 102 ms 23076 KB Output is correct
109 Correct 87 ms 23232 KB Output is correct