답안 #796047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796047 2023-07-28T05:24:18 Z 박영우(#10072) Council (JOI23_council) C++17
70 / 100
4000 ms 14136 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];
inline void add(int x) {
	if (dp[x] == popc[x]) return;
	dp[x] = popc[x];
	queue<int> q;
	q.push(x);
	int t, v;
	while (q.size()) {
		t = v = q.front();
		q.pop();
		while (v) {
			x = (v & -v);
			if (dp[x ^ t] != popc[x ^ t]) {
				dp[x ^ t] = popc[x ^ t];
				q.push(x ^ t);
			}
			v ^= x;
		}
	}
}
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 8560 KB Output is correct
3 Correct 6 ms 8532 KB Output is correct
4 Correct 6 ms 8556 KB Output is correct
5 Correct 3109 ms 8852 KB Output is correct
6 Correct 2659 ms 8536 KB Output is correct
7 Correct 2660 ms 8568 KB Output is correct
8 Correct 2648 ms 8548 KB Output is correct
9 Correct 2890 ms 8588 KB Output is correct
10 Correct 2692 ms 8544 KB Output is correct
11 Correct 2660 ms 8536 KB Output is correct
12 Correct 2860 ms 8708 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8556 KB Output is correct
15 Correct 7 ms 8472 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 6 ms 8528 KB Output is correct
18 Correct 6 ms 8548 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 6 ms 8532 KB Output is correct
21 Correct 6 ms 8552 KB Output is correct
22 Correct 8 ms 8532 KB Output is correct
23 Correct 6 ms 8556 KB Output is correct
24 Correct 6 ms 8532 KB Output is correct
25 Correct 6 ms 8532 KB Output is correct
26 Correct 6 ms 8532 KB Output is correct
27 Correct 6 ms 8532 KB Output is correct
28 Correct 6 ms 8532 KB Output is correct
29 Correct 6 ms 8532 KB Output is correct
30 Correct 8 ms 8560 KB Output is correct
31 Correct 8 ms 8560 KB Output is correct
32 Correct 7 ms 8532 KB Output is correct
33 Correct 7 ms 8512 KB Output is correct
34 Correct 7 ms 8472 KB Output is correct
35 Correct 8 ms 8532 KB Output is correct
36 Correct 6 ms 8532 KB Output is correct
37 Correct 6 ms 8532 KB Output is correct
38 Correct 7 ms 8556 KB Output is correct
39 Correct 7 ms 8556 KB Output is correct
40 Correct 9 ms 8564 KB Output is correct
41 Correct 39 ms 8532 KB Output is correct
42 Correct 35 ms 8556 KB Output is correct
43 Correct 37 ms 8540 KB Output is correct
44 Correct 36 ms 8532 KB Output is correct
45 Correct 37 ms 8532 KB Output is correct
46 Correct 313 ms 8568 KB Output is correct
47 Correct 308 ms 8532 KB Output is correct
48 Correct 305 ms 8556 KB Output is correct
49 Correct 334 ms 8548 KB Output is correct
50 Correct 283 ms 8552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 13 ms 8560 KB Output is correct
3 Correct 6 ms 8532 KB Output is correct
4 Correct 6 ms 8556 KB Output is correct
5 Correct 3109 ms 8852 KB Output is correct
6 Correct 2659 ms 8536 KB Output is correct
7 Correct 2660 ms 8568 KB Output is correct
8 Correct 2648 ms 8548 KB Output is correct
9 Correct 2890 ms 8588 KB Output is correct
10 Correct 2692 ms 8544 KB Output is correct
11 Correct 2660 ms 8536 KB Output is correct
12 Correct 2860 ms 8708 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8556 KB Output is correct
15 Correct 7 ms 8472 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 6 ms 8528 KB Output is correct
18 Correct 6 ms 8548 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 6 ms 8532 KB Output is correct
21 Correct 6 ms 8552 KB Output is correct
22 Correct 8 ms 8532 KB Output is correct
23 Correct 6 ms 8556 KB Output is correct
24 Correct 6 ms 8532 KB Output is correct
25 Correct 6 ms 8532 KB Output is correct
26 Correct 6 ms 8532 KB Output is correct
27 Correct 6 ms 8532 KB Output is correct
28 Correct 6 ms 8532 KB Output is correct
29 Correct 6 ms 8532 KB Output is correct
30 Correct 8 ms 8560 KB Output is correct
31 Correct 8 ms 8560 KB Output is correct
32 Correct 7 ms 8532 KB Output is correct
33 Correct 7 ms 8512 KB Output is correct
34 Correct 7 ms 8472 KB Output is correct
35 Correct 8 ms 8532 KB Output is correct
36 Correct 6 ms 8532 KB Output is correct
37 Correct 6 ms 8532 KB Output is correct
38 Correct 7 ms 8556 KB Output is correct
39 Correct 7 ms 8556 KB Output is correct
40 Correct 9 ms 8564 KB Output is correct
41 Correct 39 ms 8532 KB Output is correct
42 Correct 35 ms 8556 KB Output is correct
43 Correct 37 ms 8540 KB Output is correct
44 Correct 36 ms 8532 KB Output is correct
45 Correct 37 ms 8532 KB Output is correct
46 Correct 313 ms 8568 KB Output is correct
47 Correct 308 ms 8532 KB Output is correct
48 Correct 305 ms 8556 KB Output is correct
49 Correct 334 ms 8548 KB Output is correct
50 Correct 283 ms 8552 KB Output is correct
51 Correct 2591 ms 8560 KB Output is correct
52 Execution timed out 4075 ms 9376 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8556 KB Output is correct
2 Correct 74 ms 11392 KB Output is correct
3 Correct 78 ms 11416 KB Output is correct
4 Correct 71 ms 11392 KB Output is correct
5 Correct 83 ms 11392 KB Output is correct
6 Correct 68 ms 12568 KB Output is correct
7 Correct 82 ms 13744 KB Output is correct
8 Correct 6 ms 8532 KB Output is correct
9 Correct 6 ms 8532 KB Output is correct
10 Correct 6 ms 8532 KB Output is correct
11 Correct 6 ms 8552 KB Output is correct
12 Correct 6 ms 8532 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 8532 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 7 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8556 KB Output is correct
2 Correct 74 ms 11392 KB Output is correct
3 Correct 78 ms 11416 KB Output is correct
4 Correct 71 ms 11392 KB Output is correct
5 Correct 83 ms 11392 KB Output is correct
6 Correct 68 ms 12568 KB Output is correct
7 Correct 82 ms 13744 KB Output is correct
8 Correct 6 ms 8532 KB Output is correct
9 Correct 6 ms 8532 KB Output is correct
10 Correct 6 ms 8532 KB Output is correct
11 Correct 6 ms 8552 KB Output is correct
12 Correct 6 ms 8532 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 8532 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 7 ms 8532 KB Output is correct
18 Correct 7 ms 8532 KB Output is correct
19 Correct 8 ms 8532 KB Output is correct
20 Correct 202 ms 12600 KB Output is correct
21 Correct 176 ms 13712 KB Output is correct
22 Correct 175 ms 13800 KB Output is correct
23 Correct 172 ms 11732 KB Output is correct
24 Correct 194 ms 11452 KB Output is correct
25 Correct 196 ms 11392 KB Output is correct
26 Correct 197 ms 13728 KB Output is correct
27 Correct 9 ms 8560 KB Output is correct
28 Correct 6 ms 8564 KB Output is correct
29 Correct 6 ms 8556 KB Output is correct
30 Correct 6 ms 8532 KB Output is correct
31 Correct 8 ms 8556 KB Output is correct
32 Correct 6 ms 8504 KB Output is correct
33 Correct 6 ms 8552 KB Output is correct
34 Correct 7 ms 8532 KB Output is correct
35 Correct 7 ms 8532 KB Output is correct
36 Correct 8 ms 8560 KB Output is correct
37 Correct 6 ms 8556 KB Output is correct
38 Correct 6 ms 8532 KB Output is correct
39 Correct 6 ms 8532 KB Output is correct
40 Correct 6 ms 8496 KB Output is correct
41 Correct 7 ms 8532 KB Output is correct
42 Correct 6 ms 8432 KB Output is correct
43 Correct 7 ms 8552 KB Output is correct
44 Correct 8 ms 8532 KB Output is correct
45 Correct 8 ms 8532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8556 KB Output is correct
2 Correct 74 ms 11392 KB Output is correct
3 Correct 78 ms 11416 KB Output is correct
4 Correct 71 ms 11392 KB Output is correct
5 Correct 83 ms 11392 KB Output is correct
6 Correct 68 ms 12568 KB Output is correct
7 Correct 82 ms 13744 KB Output is correct
8 Correct 6 ms 8532 KB Output is correct
9 Correct 6 ms 8532 KB Output is correct
10 Correct 6 ms 8532 KB Output is correct
11 Correct 6 ms 8552 KB Output is correct
12 Correct 6 ms 8532 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 8532 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 7 ms 8532 KB Output is correct
18 Correct 7 ms 8532 KB Output is correct
19 Correct 8 ms 8532 KB Output is correct
20 Correct 202 ms 12600 KB Output is correct
21 Correct 176 ms 13712 KB Output is correct
22 Correct 175 ms 13800 KB Output is correct
23 Correct 172 ms 11732 KB Output is correct
24 Correct 194 ms 11452 KB Output is correct
25 Correct 196 ms 11392 KB Output is correct
26 Correct 197 ms 13728 KB Output is correct
27 Correct 9 ms 8560 KB Output is correct
28 Correct 6 ms 8564 KB Output is correct
29 Correct 6 ms 8556 KB Output is correct
30 Correct 6 ms 8532 KB Output is correct
31 Correct 8 ms 8556 KB Output is correct
32 Correct 6 ms 8504 KB Output is correct
33 Correct 6 ms 8552 KB Output is correct
34 Correct 7 ms 8532 KB Output is correct
35 Correct 7 ms 8532 KB Output is correct
36 Correct 8 ms 8560 KB Output is correct
37 Correct 6 ms 8556 KB Output is correct
38 Correct 6 ms 8532 KB Output is correct
39 Correct 6 ms 8532 KB Output is correct
40 Correct 6 ms 8496 KB Output is correct
41 Correct 7 ms 8532 KB Output is correct
42 Correct 6 ms 8432 KB Output is correct
43 Correct 7 ms 8552 KB Output is correct
44 Correct 8 ms 8532 KB Output is correct
45 Correct 8 ms 8532 KB Output is correct
46 Correct 13 ms 8552 KB Output is correct
47 Correct 288 ms 12596 KB Output is correct
48 Correct 260 ms 13728 KB Output is correct
49 Correct 269 ms 13760 KB Output is correct
50 Correct 237 ms 11748 KB Output is correct
51 Correct 254 ms 11420 KB Output is correct
52 Correct 298 ms 11368 KB Output is correct
53 Correct 303 ms 14080 KB Output is correct
54 Correct 41 ms 8532 KB Output is correct
55 Correct 38 ms 8532 KB Output is correct
56 Correct 38 ms 8532 KB Output is correct
57 Correct 38 ms 8532 KB Output is correct
58 Correct 38 ms 8544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8556 KB Output is correct
2 Correct 74 ms 11392 KB Output is correct
3 Correct 78 ms 11416 KB Output is correct
4 Correct 71 ms 11392 KB Output is correct
5 Correct 83 ms 11392 KB Output is correct
6 Correct 68 ms 12568 KB Output is correct
7 Correct 82 ms 13744 KB Output is correct
8 Correct 6 ms 8532 KB Output is correct
9 Correct 6 ms 8532 KB Output is correct
10 Correct 6 ms 8532 KB Output is correct
11 Correct 6 ms 8552 KB Output is correct
12 Correct 6 ms 8532 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 8532 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 7 ms 8532 KB Output is correct
18 Correct 7 ms 8532 KB Output is correct
19 Correct 8 ms 8532 KB Output is correct
20 Correct 202 ms 12600 KB Output is correct
21 Correct 176 ms 13712 KB Output is correct
22 Correct 175 ms 13800 KB Output is correct
23 Correct 172 ms 11732 KB Output is correct
24 Correct 194 ms 11452 KB Output is correct
25 Correct 196 ms 11392 KB Output is correct
26 Correct 197 ms 13728 KB Output is correct
27 Correct 9 ms 8560 KB Output is correct
28 Correct 6 ms 8564 KB Output is correct
29 Correct 6 ms 8556 KB Output is correct
30 Correct 6 ms 8532 KB Output is correct
31 Correct 8 ms 8556 KB Output is correct
32 Correct 6 ms 8504 KB Output is correct
33 Correct 6 ms 8552 KB Output is correct
34 Correct 7 ms 8532 KB Output is correct
35 Correct 7 ms 8532 KB Output is correct
36 Correct 8 ms 8560 KB Output is correct
37 Correct 6 ms 8556 KB Output is correct
38 Correct 6 ms 8532 KB Output is correct
39 Correct 6 ms 8532 KB Output is correct
40 Correct 6 ms 8496 KB Output is correct
41 Correct 7 ms 8532 KB Output is correct
42 Correct 6 ms 8432 KB Output is correct
43 Correct 7 ms 8552 KB Output is correct
44 Correct 8 ms 8532 KB Output is correct
45 Correct 8 ms 8532 KB Output is correct
46 Correct 13 ms 8552 KB Output is correct
47 Correct 288 ms 12596 KB Output is correct
48 Correct 260 ms 13728 KB Output is correct
49 Correct 269 ms 13760 KB Output is correct
50 Correct 237 ms 11748 KB Output is correct
51 Correct 254 ms 11420 KB Output is correct
52 Correct 298 ms 11368 KB Output is correct
53 Correct 303 ms 14080 KB Output is correct
54 Correct 41 ms 8532 KB Output is correct
55 Correct 38 ms 8532 KB Output is correct
56 Correct 38 ms 8532 KB Output is correct
57 Correct 38 ms 8532 KB Output is correct
58 Correct 38 ms 8544 KB Output is correct
59 Correct 527 ms 11712 KB Output is correct
60 Correct 549 ms 10640 KB Output is correct
61 Correct 543 ms 10744 KB Output is correct
62 Correct 552 ms 10924 KB Output is correct
63 Correct 494 ms 12620 KB Output is correct
64 Correct 750 ms 13828 KB Output is correct
65 Correct 729 ms 13788 KB Output is correct
66 Correct 546 ms 11780 KB Output is correct
67 Correct 653 ms 11508 KB Output is correct
68 Correct 756 ms 11544 KB Output is correct
69 Correct 767 ms 14136 KB Output is correct
70 Correct 312 ms 8572 KB Output is correct
71 Correct 275 ms 8544 KB Output is correct
72 Correct 294 ms 8536 KB Output is correct
73 Correct 277 ms 8552 KB Output is correct
74 Correct 311 ms 8552 KB Output is correct
75 Correct 375 ms 8600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8532 KB Output is correct
2 Correct 13 ms 8560 KB Output is correct
3 Correct 6 ms 8532 KB Output is correct
4 Correct 6 ms 8556 KB Output is correct
5 Correct 3109 ms 8852 KB Output is correct
6 Correct 2659 ms 8536 KB Output is correct
7 Correct 2660 ms 8568 KB Output is correct
8 Correct 2648 ms 8548 KB Output is correct
9 Correct 2890 ms 8588 KB Output is correct
10 Correct 2692 ms 8544 KB Output is correct
11 Correct 2660 ms 8536 KB Output is correct
12 Correct 2860 ms 8708 KB Output is correct
13 Correct 6 ms 8532 KB Output is correct
14 Correct 6 ms 8556 KB Output is correct
15 Correct 7 ms 8472 KB Output is correct
16 Correct 6 ms 8532 KB Output is correct
17 Correct 6 ms 8528 KB Output is correct
18 Correct 6 ms 8548 KB Output is correct
19 Correct 6 ms 8532 KB Output is correct
20 Correct 6 ms 8532 KB Output is correct
21 Correct 6 ms 8552 KB Output is correct
22 Correct 8 ms 8532 KB Output is correct
23 Correct 6 ms 8556 KB Output is correct
24 Correct 6 ms 8532 KB Output is correct
25 Correct 6 ms 8532 KB Output is correct
26 Correct 6 ms 8532 KB Output is correct
27 Correct 6 ms 8532 KB Output is correct
28 Correct 6 ms 8532 KB Output is correct
29 Correct 6 ms 8532 KB Output is correct
30 Correct 8 ms 8560 KB Output is correct
31 Correct 8 ms 8560 KB Output is correct
32 Correct 7 ms 8532 KB Output is correct
33 Correct 7 ms 8512 KB Output is correct
34 Correct 7 ms 8472 KB Output is correct
35 Correct 8 ms 8532 KB Output is correct
36 Correct 6 ms 8532 KB Output is correct
37 Correct 6 ms 8532 KB Output is correct
38 Correct 7 ms 8556 KB Output is correct
39 Correct 7 ms 8556 KB Output is correct
40 Correct 9 ms 8564 KB Output is correct
41 Correct 39 ms 8532 KB Output is correct
42 Correct 35 ms 8556 KB Output is correct
43 Correct 37 ms 8540 KB Output is correct
44 Correct 36 ms 8532 KB Output is correct
45 Correct 37 ms 8532 KB Output is correct
46 Correct 313 ms 8568 KB Output is correct
47 Correct 308 ms 8532 KB Output is correct
48 Correct 305 ms 8556 KB Output is correct
49 Correct 334 ms 8548 KB Output is correct
50 Correct 283 ms 8552 KB Output is correct
51 Correct 2591 ms 8560 KB Output is correct
52 Execution timed out 4075 ms 9376 KB Time limit exceeded
53 Halted 0 ms 0 KB -