답안 #1086918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086918 2024-09-11T17:46:57 Z daoquanglinh2007 Council (JOI23_council) C++17
40 / 100
4000 ms 11860 KB
#include <bits/stdc++.h>
using namespace std;

const int NM = 3e5, MM = 20;

int N, M, msk[NM+5], occ[(1<<MM)+5], cnt[MM+5];
int f[(1<<MM)+5], g[(1<<MM)+5];

void optimize(int i, int x){
    if (f[i] == -1 || __builtin_popcount(x&i) < __builtin_popcount(f[i]&i) || (__builtin_popcount(x&i) == __builtin_popcount(f[i]&i) && x > f[i])){
        g[i] = f[i];
        f[i] = x;
        return;
    }
    if (x == f[i]) return;
    if (g[i] == -1 || __builtin_popcount(x&i) < __builtin_popcount(g[i]&i) || (__builtin_popcount(x&i) == __builtin_popcount(g[i]&i) && x > g[i])){
        g[i] = x;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M;
    for (int i = 1; i <= N; i++){
        for (int j = 0; j < M; j++){
            char ch; cin >> ch;
            if (ch == '1'){
                msk[i] += 1<<j;
                cnt[j]++;
            }
        }
        occ[msk[i]]++;
    }
    for (int i = 0; i < (1<<M); i++)
        f[i] = g[i] = -1;
    for (int i = 0; i < (1<<M); i++)
        for (int j = 0; j < (1<<M); j++){
            if (!occ[j]) continue;
            optimize(i, j);
        }
    for (int i = 1; i <= N; i++){
        int tmp = 0, res = 0;
        for (int j = 0; j < M; j++){
            if (cnt[j]-((msk[i]>>j)&1) >= N/2) res++;
            if (cnt[j]-((msk[i]>>j)&1) == N/2) tmp += (1<<j);
        }
        if (f[tmp] == msk[i] && occ[msk[i]] == 1) res -= __builtin_popcount(g[tmp]&tmp);
        else res -= __builtin_popcount(f[tmp]&tmp);

        cout << res << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 4088 ms 8656 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 4088 ms 8656 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 21 ms 3392 KB Output is correct
3 Correct 22 ms 2140 KB Output is correct
4 Correct 20 ms 2720 KB Output is correct
5 Correct 27 ms 3412 KB Output is correct
6 Correct 24 ms 2652 KB Output is correct
7 Correct 24 ms 3212 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 21 ms 3392 KB Output is correct
3 Correct 22 ms 2140 KB Output is correct
4 Correct 20 ms 2720 KB Output is correct
5 Correct 27 ms 3412 KB Output is correct
6 Correct 24 ms 2652 KB Output is correct
7 Correct 24 ms 3212 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 77 ms 7792 KB Output is correct
21 Correct 66 ms 7248 KB Output is correct
22 Correct 65 ms 7164 KB Output is correct
23 Correct 47 ms 8276 KB Output is correct
24 Correct 44 ms 6736 KB Output is correct
25 Correct 73 ms 8072 KB Output is correct
26 Correct 79 ms 8016 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 4 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 21 ms 3392 KB Output is correct
3 Correct 22 ms 2140 KB Output is correct
4 Correct 20 ms 2720 KB Output is correct
5 Correct 27 ms 3412 KB Output is correct
6 Correct 24 ms 2652 KB Output is correct
7 Correct 24 ms 3212 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 77 ms 7792 KB Output is correct
21 Correct 66 ms 7248 KB Output is correct
22 Correct 65 ms 7164 KB Output is correct
23 Correct 47 ms 8276 KB Output is correct
24 Correct 44 ms 6736 KB Output is correct
25 Correct 73 ms 8072 KB Output is correct
26 Correct 79 ms 8016 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 4 ms 508 KB Output is correct
46 Correct 17 ms 344 KB Output is correct
47 Correct 902 ms 10596 KB Output is correct
48 Correct 299 ms 9808 KB Output is correct
49 Correct 292 ms 10072 KB Output is correct
50 Correct 325 ms 10832 KB Output is correct
51 Correct 328 ms 9296 KB Output is correct
52 Correct 2604 ms 10464 KB Output is correct
53 Correct 2647 ms 10836 KB Output is correct
54 Correct 268 ms 464 KB Output is correct
55 Correct 265 ms 604 KB Output is correct
56 Correct 282 ms 604 KB Output is correct
57 Correct 267 ms 604 KB Output is correct
58 Correct 270 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 21 ms 3392 KB Output is correct
3 Correct 22 ms 2140 KB Output is correct
4 Correct 20 ms 2720 KB Output is correct
5 Correct 27 ms 3412 KB Output is correct
6 Correct 24 ms 2652 KB Output is correct
7 Correct 24 ms 3212 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 77 ms 7792 KB Output is correct
21 Correct 66 ms 7248 KB Output is correct
22 Correct 65 ms 7164 KB Output is correct
23 Correct 47 ms 8276 KB Output is correct
24 Correct 44 ms 6736 KB Output is correct
25 Correct 73 ms 8072 KB Output is correct
26 Correct 79 ms 8016 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 468 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 348 KB Output is correct
45 Correct 4 ms 508 KB Output is correct
46 Correct 17 ms 344 KB Output is correct
47 Correct 902 ms 10596 KB Output is correct
48 Correct 299 ms 9808 KB Output is correct
49 Correct 292 ms 10072 KB Output is correct
50 Correct 325 ms 10832 KB Output is correct
51 Correct 328 ms 9296 KB Output is correct
52 Correct 2604 ms 10464 KB Output is correct
53 Correct 2647 ms 10836 KB Output is correct
54 Correct 268 ms 464 KB Output is correct
55 Correct 265 ms 604 KB Output is correct
56 Correct 282 ms 604 KB Output is correct
57 Correct 267 ms 604 KB Output is correct
58 Correct 270 ms 600 KB Output is correct
59 Execution timed out 4066 ms 11860 KB Time limit exceeded
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 17 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Execution timed out 4088 ms 8656 KB Time limit exceeded
6 Halted 0 ms 0 KB -