답안 #1086965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086965 2024-09-12T00:25:46 Z daoquanglinh2007 Council (JOI23_council) C++17
6 / 100
457 ms 205680 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][MM+5], g[(1<<MM)+5][MM+5];
 
void optimize(int i, int j, int x){
    if (f[i][j] == -1 || __builtin_popcount(x&i) < __builtin_popcount(f[i][j]&i)){
        g[i][j] = f[i][j];
        f[i][j] = x;
        return;
    }
    if (x == f[i][j]) return;
    if (g[i][j] == -1 || __builtin_popcount(x&i) < __builtin_popcount(g[i][j]&i)){
        g[i][j] = 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][0] = (occ[i] > 0 ? i : -1);
        g[i][0] = -1;
    }
    for (int i = 0; i < (1<<M); i++)
        for (int j = 0; j < M; j++){
            f[i][j+1] = f[i][j];
            g[i][j+1] = g[i][j];
            if (((i>>j)&1) == 1){
                optimize(i, j+1, f[i-(1<<j)][j]);
                optimize(i, j+1, g[i-(1<<j)][j]);
            }
        }
    for (int i = (1<<M)-1; i >= 0; i--){
        f[i][0] = f[i][M];
        g[i][0] = g[i][M];
        for (int j = 0; j < M; j++){
            f[i][j+1] = f[i][j];
            g[i][j+1] = g[i][j];
            if (((i>>j)&1) == 0){
                optimize(i, j+1, f[i+(1<<j)][j]);
                optimize(i, j+1, g[i+(1<<j)][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][M] == msk[i] && occ[msk[i]] == 1) res -= __builtin_popcount(g[tmp][M]&tmp);
        else res -= __builtin_popcount(f[tmp][M]&tmp);
 
        cout << res << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 431 ms 205680 KB Output is correct
6 Correct 402 ms 205668 KB Output is correct
7 Incorrect 457 ms 205460 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 431 ms 205680 KB Output is correct
6 Correct 402 ms 205668 KB Output is correct
7 Incorrect 457 ms 205460 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 20 ms 3420 KB Output is correct
3 Correct 20 ms 2116 KB Output is correct
4 Correct 20 ms 2652 KB Output is correct
5 Correct 24 ms 3672 KB Output is correct
6 Correct 20 ms 2652 KB Output is correct
7 Correct 30 ms 3432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 20 ms 3420 KB Output is correct
3 Correct 20 ms 2116 KB Output is correct
4 Correct 20 ms 2652 KB Output is correct
5 Correct 24 ms 3672 KB Output is correct
6 Correct 20 ms 2652 KB Output is correct
7 Correct 30 ms 3432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 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 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 70 ms 8168 KB Output is correct
21 Correct 63 ms 7476 KB Output is correct
22 Incorrect 60 ms 7508 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 20 ms 3420 KB Output is correct
3 Correct 20 ms 2116 KB Output is correct
4 Correct 20 ms 2652 KB Output is correct
5 Correct 24 ms 3672 KB Output is correct
6 Correct 20 ms 2652 KB Output is correct
7 Correct 30 ms 3432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 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 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 70 ms 8168 KB Output is correct
21 Correct 63 ms 7476 KB Output is correct
22 Incorrect 60 ms 7508 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 20 ms 3420 KB Output is correct
3 Correct 20 ms 2116 KB Output is correct
4 Correct 20 ms 2652 KB Output is correct
5 Correct 24 ms 3672 KB Output is correct
6 Correct 20 ms 2652 KB Output is correct
7 Correct 30 ms 3432 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 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 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 70 ms 8168 KB Output is correct
21 Correct 63 ms 7476 KB Output is correct
22 Incorrect 60 ms 7508 KB Output isn't correct
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 431 ms 205680 KB Output is correct
6 Correct 402 ms 205668 KB Output is correct
7 Incorrect 457 ms 205460 KB Output isn't correct
8 Halted 0 ms 0 KB -