답안 #893395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893395 2023-12-27T04:18:45 Z ksujay2 Council (JOI23_council) C++17
8 / 100
1659 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
const int BS = 550;
const int INF = 1e9;
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N, M; cin >> N >> M;
    vector<int> A(N);
    vector<int> cnt(M);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            int a; cin >> a;
            A[i] += a << j;
            cnt[j] += a;
        }
    }
    vector<int> D;
    for(int i = 0; i < N; i++) {
        if(i % BS == 0) {
            D = vector<int>(1 << M, INF);
            queue<int> q;
            for(int j = 0; j < N; j++) {
                if(j < i || i + BS <= j) {
                    D[A[j]] = 0;
                    q.push(A[j]);
                }
            }
            function<void(int)> dfs = [&] (int s) {
                for(int j = 0; j < M; j++) {
                    if(D[s ^ (1 << j)] > D[s]) {
                        if((s & (1 << j)) > 0) {
                            D[s ^ (1 << j)] = D[s] + 1;
                            q.push(s ^ (1 << j));
                        } else {
                            D[s ^ (1 << j)] = D[s];
                            dfs(s ^ (1 << j));
                        }
                    }
                }
            };
            while(q.size() > 0) {
                int s = q.front();
                dfs(s);
            }
        }
        int v = (1 << M) - 1;
        int ans = 0;
        for(int j = 0; j < M; j++) {
            int c = (cnt[j] - ((A[i] & (1 << j)) > 0));
            if(c == N / 2) {
                v ^= 1 << j;
            }
            if(c >= N / 2) ans++;
        }
        int best = D[v];
        for(int j = i - (i % BS); j < (i - (i % BS) + BS) && j < N; j++) {
            if(j != i) {
                best = min(best, __popcount(A[j] ^ (A[j] & v)));
            }
        }
        cout << ans - best << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 Correct 1 ms 4444 KB Output is correct
6 Correct 3 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 352 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 356 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 352 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 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 352 KB Output is correct
46 Correct 1 ms 856 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 0 ms 860 KB Output is correct
49 Correct 0 ms 860 KB Output is correct
50 Correct 0 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 Correct 1 ms 4444 KB Output is correct
6 Correct 3 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 352 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 356 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 352 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 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 352 KB Output is correct
46 Correct 1 ms 856 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 0 ms 860 KB Output is correct
49 Correct 0 ms 860 KB Output is correct
50 Correct 0 ms 860 KB Output is correct
51 Runtime error 1169 ms 1048576 KB Execution killed with signal 9
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1659 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1659 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1659 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1659 ms 1048576 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 Correct 1 ms 4444 KB Output is correct
6 Correct 3 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 2 ms 4444 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 352 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 356 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 352 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 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 352 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 352 KB Output is correct
46 Correct 1 ms 856 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 0 ms 860 KB Output is correct
49 Correct 0 ms 860 KB Output is correct
50 Correct 0 ms 860 KB Output is correct
51 Runtime error 1169 ms 1048576 KB Execution killed with signal 9
52 Halted 0 ms 0 KB -