답안 #796039

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796039 2023-07-28T05:16:55 Z 박영우(#10072) Council (JOI23_council) C++17
70 / 100
4000 ms 14120 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 301010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
int A[MAX];
int popc[1 << MAXS];
int dp[1 << MAXS];
int ans[MAX];
int cmask[MAX];
int sum[MAXS];
void add(int x) {
	if (dp[x] == popc[x]) return;
	else dp[x] = popc[x];
	int i;
	for (i = 0; i < MAXS; i++) if (x >> i & 1) add(x ^ (1 << i));
}
int num[MAX];
int pl[MAX];
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, M;
	cin >> N >> M;
	int l = N / 2;
	int i, j;
	for (i = 1; i <= N; i++) {
		int a;
		for (j = 0; j < M; j++) cin >> a, A[i] |= (a << j), sum[j] += a;
	}
	int allsum = 0;
	for (i = 0; i < M; i++) {
		if (sum[i] >= l + 2) allsum++, num[i] = 3;
		if (sum[i] == l + 1) num[i] = 2;
		if (sum[i] == l) num[i] = 1;
	}
	for (i = 0; i < (1 << MAXS); i++) popc[i] = __builtin_popcount(i);
	int K = 1 << M;
	K--;
	for (i = 1; i <= N; i++) {
		for (j = 0; j < M; j++) {
			if (A[i] >> j & 1) { if (num[j] == 2) cmask[i] |= (1 << j); }
			else {
				if (num[j] == 1) cmask[i] |= (1 << j);
				if (num[j] == 2) pl[i]++;
			}
		}
	}
	int k;
	for (k = 0; k < MAXS; k++) {
		memset(dp, 0, sizeof(dp));
		for (i = 1; i <= N; i++) if (i >> k & 1) add(K ^ A[i]);
		for (i = 0; i <= K; i++) for (j = 0; j < M; j++) if (i >> j & 1) dp[i] = max(dp[i], dp[i ^ (1 << j)]);
		for (i = 1; i <= N; i++) if (!(i >> k & 1)) ans[i] = max(ans[i], dp[cmask[i]]);
		memset(dp, 0, sizeof(dp));
		for (i = 1; i <= N; i++) if (!(i >> k & 1)) add(K ^ A[i]);
		for (i = 0; i <= K; i++) for (j = 0; j < M; j++) if (i >> j & 1) dp[i] = max(dp[i], dp[i ^ (1 << j)]);
		for (i = 1; i <= N; i++) if (i >> k & 1) ans[i] = max(ans[i], dp[cmask[i]]);
	}
	for (i = 1; i <= N; i++) cout << ans[i] + allsum + pl[i] << ln;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 13 ms 8512 KB Output is correct
3 Correct 7 ms 8552 KB Output is correct
4 Correct 6 ms 8532 KB Output is correct
5 Correct 3450 ms 8536 KB Output is correct
6 Correct 2578 ms 8532 KB Output is correct
7 Correct 2617 ms 8536 KB Output is correct
8 Correct 2582 ms 8532 KB Output is correct
9 Correct 3162 ms 8548 KB Output is correct
10 Correct 2568 ms 8532 KB Output is correct
11 Correct 2585 ms 8540 KB Output is correct
12 Correct 3134 ms 8536 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8552 KB Output is correct
15 Correct 6 ms 8432 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 6 ms 8532 KB Output is correct
18 Correct 7 ms 8560 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 6 ms 8552 KB Output is correct
21 Correct 7 ms 8532 KB Output is correct
22 Correct 10 ms 8532 KB Output is correct
23 Correct 8 ms 8576 KB Output is correct
24 Correct 7 ms 8532 KB Output is correct
25 Correct 6 ms 8532 KB Output is correct
26 Correct 6 ms 8556 KB Output is correct
27 Correct 6 ms 8532 KB Output is correct
28 Correct 6 ms 8548 KB Output is correct
29 Correct 6 ms 8532 KB Output is correct
30 Correct 8 ms 8476 KB Output is correct
31 Correct 9 ms 8564 KB Output is correct
32 Correct 6 ms 8532 KB Output is correct
33 Correct 6 ms 8532 KB Output is correct
34 Correct 6 ms 8532 KB Output is correct
35 Correct 6 ms 8532 KB Output is correct
36 Correct 6 ms 8532 KB Output is correct
37 Correct 7 ms 8560 KB Output is correct
38 Correct 7 ms 8560 KB Output is correct
39 Correct 10 ms 8552 KB Output is correct
40 Correct 9 ms 8564 KB Output is correct
41 Correct 46 ms 8556 KB Output is correct
42 Correct 37 ms 8672 KB Output is correct
43 Correct 39 ms 8532 KB Output is correct
44 Correct 36 ms 8536 KB Output is correct
45 Correct 36 ms 8532 KB Output is correct
46 Correct 363 ms 8556 KB Output is correct
47 Correct 274 ms 8532 KB Output is correct
48 Correct 278 ms 8552 KB Output is correct
49 Correct 274 ms 8544 KB Output is correct
50 Correct 292 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 13 ms 8512 KB Output is correct
3 Correct 7 ms 8552 KB Output is correct
4 Correct 6 ms 8532 KB Output is correct
5 Correct 3450 ms 8536 KB Output is correct
6 Correct 2578 ms 8532 KB Output is correct
7 Correct 2617 ms 8536 KB Output is correct
8 Correct 2582 ms 8532 KB Output is correct
9 Correct 3162 ms 8548 KB Output is correct
10 Correct 2568 ms 8532 KB Output is correct
11 Correct 2585 ms 8540 KB Output is correct
12 Correct 3134 ms 8536 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8552 KB Output is correct
15 Correct 6 ms 8432 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 6 ms 8532 KB Output is correct
18 Correct 7 ms 8560 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 6 ms 8552 KB Output is correct
21 Correct 7 ms 8532 KB Output is correct
22 Correct 10 ms 8532 KB Output is correct
23 Correct 8 ms 8576 KB Output is correct
24 Correct 7 ms 8532 KB Output is correct
25 Correct 6 ms 8532 KB Output is correct
26 Correct 6 ms 8556 KB Output is correct
27 Correct 6 ms 8532 KB Output is correct
28 Correct 6 ms 8548 KB Output is correct
29 Correct 6 ms 8532 KB Output is correct
30 Correct 8 ms 8476 KB Output is correct
31 Correct 9 ms 8564 KB Output is correct
32 Correct 6 ms 8532 KB Output is correct
33 Correct 6 ms 8532 KB Output is correct
34 Correct 6 ms 8532 KB Output is correct
35 Correct 6 ms 8532 KB Output is correct
36 Correct 6 ms 8532 KB Output is correct
37 Correct 7 ms 8560 KB Output is correct
38 Correct 7 ms 8560 KB Output is correct
39 Correct 10 ms 8552 KB Output is correct
40 Correct 9 ms 8564 KB Output is correct
41 Correct 46 ms 8556 KB Output is correct
42 Correct 37 ms 8672 KB Output is correct
43 Correct 39 ms 8532 KB Output is correct
44 Correct 36 ms 8536 KB Output is correct
45 Correct 36 ms 8532 KB Output is correct
46 Correct 363 ms 8556 KB Output is correct
47 Correct 274 ms 8532 KB Output is correct
48 Correct 278 ms 8552 KB Output is correct
49 Correct 274 ms 8544 KB Output is correct
50 Correct 292 ms 8532 KB Output is correct
51 Correct 2542 ms 8564 KB Output is correct
52 Execution timed out 4051 ms 8548 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 93 ms 11396 KB Output is correct
3 Correct 79 ms 11396 KB Output is correct
4 Correct 62 ms 11392 KB Output is correct
5 Correct 76 ms 11512 KB Output is correct
6 Correct 65 ms 12572 KB Output is correct
7 Correct 77 ms 13736 KB Output is correct
8 Correct 7 ms 8532 KB Output is correct
9 Correct 8 ms 8556 KB Output is correct
10 Correct 7 ms 8532 KB Output is correct
11 Correct 7 ms 8532 KB Output is correct
12 Correct 8 ms 8528 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8532 KB Output is correct
15 Correct 6 ms 8556 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 8 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 93 ms 11396 KB Output is correct
3 Correct 79 ms 11396 KB Output is correct
4 Correct 62 ms 11392 KB Output is correct
5 Correct 76 ms 11512 KB Output is correct
6 Correct 65 ms 12572 KB Output is correct
7 Correct 77 ms 13736 KB Output is correct
8 Correct 7 ms 8532 KB Output is correct
9 Correct 8 ms 8556 KB Output is correct
10 Correct 7 ms 8532 KB Output is correct
11 Correct 7 ms 8532 KB Output is correct
12 Correct 8 ms 8528 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8532 KB Output is correct
15 Correct 6 ms 8556 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 8 ms 8532 KB Output is correct
18 Correct 6 ms 8532 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 187 ms 12564 KB Output is correct
21 Correct 175 ms 13832 KB Output is correct
22 Correct 172 ms 13736 KB Output is correct
23 Correct 166 ms 11688 KB Output is correct
24 Correct 162 ms 11468 KB Output is correct
25 Correct 193 ms 11508 KB Output is correct
26 Correct 201 ms 13772 KB Output is correct
27 Correct 8 ms 8532 KB Output is correct
28 Correct 6 ms 8552 KB Output is correct
29 Correct 6 ms 8492 KB Output is correct
30 Correct 6 ms 8496 KB Output is correct
31 Correct 6 ms 8532 KB Output is correct
32 Correct 6 ms 8532 KB Output is correct
33 Correct 7 ms 8532 KB Output is correct
34 Correct 7 ms 8532 KB Output is correct
35 Correct 11 ms 8788 KB Output is correct
36 Correct 10 ms 8556 KB Output is correct
37 Correct 6 ms 8520 KB Output is correct
38 Correct 6 ms 8440 KB Output is correct
39 Correct 6 ms 8532 KB Output is correct
40 Correct 6 ms 8448 KB Output is correct
41 Correct 6 ms 8560 KB Output is correct
42 Correct 6 ms 8560 KB Output is correct
43 Correct 7 ms 8532 KB Output is correct
44 Correct 8 ms 8552 KB Output is correct
45 Correct 11 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 93 ms 11396 KB Output is correct
3 Correct 79 ms 11396 KB Output is correct
4 Correct 62 ms 11392 KB Output is correct
5 Correct 76 ms 11512 KB Output is correct
6 Correct 65 ms 12572 KB Output is correct
7 Correct 77 ms 13736 KB Output is correct
8 Correct 7 ms 8532 KB Output is correct
9 Correct 8 ms 8556 KB Output is correct
10 Correct 7 ms 8532 KB Output is correct
11 Correct 7 ms 8532 KB Output is correct
12 Correct 8 ms 8528 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8532 KB Output is correct
15 Correct 6 ms 8556 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 8 ms 8532 KB Output is correct
18 Correct 6 ms 8532 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 187 ms 12564 KB Output is correct
21 Correct 175 ms 13832 KB Output is correct
22 Correct 172 ms 13736 KB Output is correct
23 Correct 166 ms 11688 KB Output is correct
24 Correct 162 ms 11468 KB Output is correct
25 Correct 193 ms 11508 KB Output is correct
26 Correct 201 ms 13772 KB Output is correct
27 Correct 8 ms 8532 KB Output is correct
28 Correct 6 ms 8552 KB Output is correct
29 Correct 6 ms 8492 KB Output is correct
30 Correct 6 ms 8496 KB Output is correct
31 Correct 6 ms 8532 KB Output is correct
32 Correct 6 ms 8532 KB Output is correct
33 Correct 7 ms 8532 KB Output is correct
34 Correct 7 ms 8532 KB Output is correct
35 Correct 11 ms 8788 KB Output is correct
36 Correct 10 ms 8556 KB Output is correct
37 Correct 6 ms 8520 KB Output is correct
38 Correct 6 ms 8440 KB Output is correct
39 Correct 6 ms 8532 KB Output is correct
40 Correct 6 ms 8448 KB Output is correct
41 Correct 6 ms 8560 KB Output is correct
42 Correct 6 ms 8560 KB Output is correct
43 Correct 7 ms 8532 KB Output is correct
44 Correct 8 ms 8552 KB Output is correct
45 Correct 11 ms 8532 KB Output is correct
46 Correct 14 ms 8532 KB Output is correct
47 Correct 312 ms 12636 KB Output is correct
48 Correct 256 ms 13832 KB Output is correct
49 Correct 258 ms 13760 KB Output is correct
50 Correct 266 ms 11684 KB Output is correct
51 Correct 270 ms 11396 KB Output is correct
52 Correct 317 ms 11412 KB Output is correct
53 Correct 320 ms 14076 KB Output is correct
54 Correct 49 ms 8440 KB Output is correct
55 Correct 38 ms 8552 KB Output is correct
56 Correct 42 ms 8548 KB Output is correct
57 Correct 41 ms 8532 KB Output is correct
58 Correct 40 ms 8536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 93 ms 11396 KB Output is correct
3 Correct 79 ms 11396 KB Output is correct
4 Correct 62 ms 11392 KB Output is correct
5 Correct 76 ms 11512 KB Output is correct
6 Correct 65 ms 12572 KB Output is correct
7 Correct 77 ms 13736 KB Output is correct
8 Correct 7 ms 8532 KB Output is correct
9 Correct 8 ms 8556 KB Output is correct
10 Correct 7 ms 8532 KB Output is correct
11 Correct 7 ms 8532 KB Output is correct
12 Correct 8 ms 8528 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8532 KB Output is correct
15 Correct 6 ms 8556 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 8 ms 8532 KB Output is correct
18 Correct 6 ms 8532 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 187 ms 12564 KB Output is correct
21 Correct 175 ms 13832 KB Output is correct
22 Correct 172 ms 13736 KB Output is correct
23 Correct 166 ms 11688 KB Output is correct
24 Correct 162 ms 11468 KB Output is correct
25 Correct 193 ms 11508 KB Output is correct
26 Correct 201 ms 13772 KB Output is correct
27 Correct 8 ms 8532 KB Output is correct
28 Correct 6 ms 8552 KB Output is correct
29 Correct 6 ms 8492 KB Output is correct
30 Correct 6 ms 8496 KB Output is correct
31 Correct 6 ms 8532 KB Output is correct
32 Correct 6 ms 8532 KB Output is correct
33 Correct 7 ms 8532 KB Output is correct
34 Correct 7 ms 8532 KB Output is correct
35 Correct 11 ms 8788 KB Output is correct
36 Correct 10 ms 8556 KB Output is correct
37 Correct 6 ms 8520 KB Output is correct
38 Correct 6 ms 8440 KB Output is correct
39 Correct 6 ms 8532 KB Output is correct
40 Correct 6 ms 8448 KB Output is correct
41 Correct 6 ms 8560 KB Output is correct
42 Correct 6 ms 8560 KB Output is correct
43 Correct 7 ms 8532 KB Output is correct
44 Correct 8 ms 8552 KB Output is correct
45 Correct 11 ms 8532 KB Output is correct
46 Correct 14 ms 8532 KB Output is correct
47 Correct 312 ms 12636 KB Output is correct
48 Correct 256 ms 13832 KB Output is correct
49 Correct 258 ms 13760 KB Output is correct
50 Correct 266 ms 11684 KB Output is correct
51 Correct 270 ms 11396 KB Output is correct
52 Correct 317 ms 11412 KB Output is correct
53 Correct 320 ms 14076 KB Output is correct
54 Correct 49 ms 8440 KB Output is correct
55 Correct 38 ms 8552 KB Output is correct
56 Correct 42 ms 8548 KB Output is correct
57 Correct 41 ms 8532 KB Output is correct
58 Correct 40 ms 8536 KB Output is correct
59 Correct 522 ms 11704 KB Output is correct
60 Correct 735 ms 10596 KB Output is correct
61 Correct 742 ms 10716 KB Output is correct
62 Correct 772 ms 10912 KB Output is correct
63 Correct 576 ms 12564 KB Output is correct
64 Correct 870 ms 13740 KB Output is correct
65 Correct 866 ms 13752 KB Output is correct
66 Correct 518 ms 11780 KB Output is correct
67 Correct 817 ms 11396 KB Output is correct
68 Correct 933 ms 11396 KB Output is correct
69 Correct 947 ms 14120 KB Output is correct
70 Correct 412 ms 8556 KB Output is correct
71 Correct 291 ms 8556 KB Output is correct
72 Correct 288 ms 8552 KB Output is correct
73 Correct 301 ms 8548 KB Output is correct
74 Correct 320 ms 8536 KB Output is correct
75 Correct 538 ms 8592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 13 ms 8512 KB Output is correct
3 Correct 7 ms 8552 KB Output is correct
4 Correct 6 ms 8532 KB Output is correct
5 Correct 3450 ms 8536 KB Output is correct
6 Correct 2578 ms 8532 KB Output is correct
7 Correct 2617 ms 8536 KB Output is correct
8 Correct 2582 ms 8532 KB Output is correct
9 Correct 3162 ms 8548 KB Output is correct
10 Correct 2568 ms 8532 KB Output is correct
11 Correct 2585 ms 8540 KB Output is correct
12 Correct 3134 ms 8536 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8552 KB Output is correct
15 Correct 6 ms 8432 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 6 ms 8532 KB Output is correct
18 Correct 7 ms 8560 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 6 ms 8552 KB Output is correct
21 Correct 7 ms 8532 KB Output is correct
22 Correct 10 ms 8532 KB Output is correct
23 Correct 8 ms 8576 KB Output is correct
24 Correct 7 ms 8532 KB Output is correct
25 Correct 6 ms 8532 KB Output is correct
26 Correct 6 ms 8556 KB Output is correct
27 Correct 6 ms 8532 KB Output is correct
28 Correct 6 ms 8548 KB Output is correct
29 Correct 6 ms 8532 KB Output is correct
30 Correct 8 ms 8476 KB Output is correct
31 Correct 9 ms 8564 KB Output is correct
32 Correct 6 ms 8532 KB Output is correct
33 Correct 6 ms 8532 KB Output is correct
34 Correct 6 ms 8532 KB Output is correct
35 Correct 6 ms 8532 KB Output is correct
36 Correct 6 ms 8532 KB Output is correct
37 Correct 7 ms 8560 KB Output is correct
38 Correct 7 ms 8560 KB Output is correct
39 Correct 10 ms 8552 KB Output is correct
40 Correct 9 ms 8564 KB Output is correct
41 Correct 46 ms 8556 KB Output is correct
42 Correct 37 ms 8672 KB Output is correct
43 Correct 39 ms 8532 KB Output is correct
44 Correct 36 ms 8536 KB Output is correct
45 Correct 36 ms 8532 KB Output is correct
46 Correct 363 ms 8556 KB Output is correct
47 Correct 274 ms 8532 KB Output is correct
48 Correct 278 ms 8552 KB Output is correct
49 Correct 274 ms 8544 KB Output is correct
50 Correct 292 ms 8532 KB Output is correct
51 Correct 2542 ms 8564 KB Output is correct
52 Execution timed out 4051 ms 8548 KB Time limit exceeded
53 Halted 0 ms 0 KB -