답안 #796025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
796025 2023-07-28T04:54:35 Z 반딧불(#10068) Council (JOI23_council) C++17
40 / 100
4000 ms 30812 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int INF = 1e9;

int n, k, s;
int arr[300002][22];
int sum[22];
bool caring[22];
int basis;

int bitx0, bitx1;
int val0[300002], val1[300002];
int val[300002];

int DP[1<<20][2]; /// �ڱ⸦ �����ϴ� �ּ� / �ִ� ��ȣ
pair<int, int> DP2[1<<20][2]; /// �ڱ� �Ʒ� �� ��Ʈ ���� ���� ���� �� ��

void dpmerge(int x, pair<int, int> p){
    if(p.first == -1) return;
    if(DP2[x][0].second == p.second || DP2[x][1].second == p.second){
        if(DP2[x][1].second == p.second) swap(DP2[x][0], DP2[x][1]);
        DP2[x][0].first = max(DP2[x][0].first, p.first);
        if(DP2[x][0] < DP2[x][1]) swap(DP2[x][0], DP2[x][1]);
        return;
    }
    if(DP2[x][1] < p) swap(DP2[x][1], p);
    if(DP2[x][0] < DP2[x][1]) swap(DP2[x][0], DP2[x][1]);
}

int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=n; i++) for(int j=1; j<=k; j++) scanf("%d", &arr[i][j]), sum[j] += arr[i][j];
    s = n/2;

    for(int j=1; j<=k; j++){
        if(sum[j] > s+1){
            basis++;
            continue;
        }
        if(sum[j] < s) continue;
        caring[j] = 1;
        for(int i=1; i<=n; i++){
            if(!arr[i][j]){
                if(sum[j] == s) val0[i] += (1<<(j-1));
                else val1[i] += (1<<(j-1));
            }
        }
        if(sum[j] == s) bitx0 += (1<<(j-1));
        else bitx1 += (1<<(j-1));
    }
    for(int i=1; i<=n; i++){
        val[i] = val0[i] | val1[i];
    }

    for(int i=0; i<(1<<k); i++){
        DP[i][0] = INF, DP[i][1] = 0;
        DP2[i][0] = DP2[i][1] = make_pair(-1, -1);
    }

    /// DP�� ����Ѵ�
    for(int i=1; i<=n; i++){
        DP[val[i]][0] = min(DP[val[i]][0], i);
        DP[val[i]][1] = max(DP[val[i]][1], i);
    }
    for(int i=(1<<k)-1; i>=0; i--){
        for(int j=0; j<k; j++){
            if((i>>j)&1){
                DP[i^(1<<j)][0] = min(DP[i^(1<<j)][0], DP[i][0]);
                DP[i^(1<<j)][1] = max(DP[i^(1<<j)][1], DP[i][1]);
            }
        }
    }

    /// DP2�� ����Ѵ�
    for(int i=0; i<(1<<k); i++){
        if(DP[i][0] != INF) DP2[i][0] = make_pair(__builtin_popcount(i), DP[i][0]);
        if(DP[i][1] != 0 && DP[i][1] != DP[i][0]) DP2[i][1] = make_pair(__builtin_popcount(i), DP[i][1]);
        if(DP2[i][0] < DP2[i][1]) swap(DP2[i][0], DP2[i][1]);

        for(int j=0; j<(1<<k); j++){
            if((i>>j)&1){
                dpmerge(i, DP2[i^(1<<j)][0]);
                dpmerge(i, DP2[i^(1<<j)][1]);
            }
        }
    }

    for(int i=1; i<=n; i++){
        int mine = basis + __builtin_popcount(val1[i]);
        int key = (bitx1 & ~val1[i]) | (bitx0 & val0[i]);
        int v = (DP2[key][0].second == i ? DP2[key][1].first : DP2[key][0].first);
        v = max(v, 0);
        printf("%d\n", mine + v);
    }
}

Compilation message

council.cpp: In function 'int main()':
council.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
council.cpp:35:58: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     for(int i=1; i<=n; i++) for(int j=1; j<=k; j++) scanf("%d", &arr[i][j]), sum[j] += arr[i][j];
      |                                                     ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 32 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Execution timed out 4091 ms 24916 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 32 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Execution timed out 4091 ms 24916 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 63 ms 27856 KB Output is correct
3 Correct 65 ms 27912 KB Output is correct
4 Correct 49 ms 27852 KB Output is correct
5 Correct 66 ms 27896 KB Output is correct
6 Correct 53 ms 29004 KB Output is correct
7 Correct 87 ms 30204 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 63 ms 27856 KB Output is correct
3 Correct 65 ms 27912 KB Output is correct
4 Correct 49 ms 27852 KB Output is correct
5 Correct 66 ms 27896 KB Output is correct
6 Correct 53 ms 29004 KB Output is correct
7 Correct 87 ms 30204 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 226 ms 29004 KB Output is correct
21 Correct 208 ms 30252 KB Output is correct
22 Correct 253 ms 30268 KB Output is correct
23 Correct 229 ms 28244 KB Output is correct
24 Correct 189 ms 27920 KB Output is correct
25 Correct 224 ms 27896 KB Output is correct
26 Correct 226 ms 30200 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 63 ms 27856 KB Output is correct
3 Correct 65 ms 27912 KB Output is correct
4 Correct 49 ms 27852 KB Output is correct
5 Correct 66 ms 27896 KB Output is correct
6 Correct 53 ms 29004 KB Output is correct
7 Correct 87 ms 30204 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 226 ms 29004 KB Output is correct
21 Correct 208 ms 30252 KB Output is correct
22 Correct 253 ms 30268 KB Output is correct
23 Correct 229 ms 28244 KB Output is correct
24 Correct 189 ms 27920 KB Output is correct
25 Correct 224 ms 27896 KB Output is correct
26 Correct 226 ms 30200 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 32 ms 444 KB Output is correct
47 Correct 883 ms 29384 KB Output is correct
48 Correct 434 ms 30356 KB Output is correct
49 Correct 421 ms 30412 KB Output is correct
50 Correct 822 ms 28496 KB Output is correct
51 Correct 809 ms 28216 KB Output is correct
52 Correct 825 ms 28344 KB Output is correct
53 Correct 851 ms 30812 KB Output is correct
54 Correct 550 ms 724 KB Output is correct
55 Correct 560 ms 724 KB Output is correct
56 Correct 564 ms 724 KB Output is correct
57 Correct 568 ms 724 KB Output is correct
58 Correct 584 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 63 ms 27856 KB Output is correct
3 Correct 65 ms 27912 KB Output is correct
4 Correct 49 ms 27852 KB Output is correct
5 Correct 66 ms 27896 KB Output is correct
6 Correct 53 ms 29004 KB Output is correct
7 Correct 87 ms 30204 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 226 ms 29004 KB Output is correct
21 Correct 208 ms 30252 KB Output is correct
22 Correct 253 ms 30268 KB Output is correct
23 Correct 229 ms 28244 KB Output is correct
24 Correct 189 ms 27920 KB Output is correct
25 Correct 224 ms 27896 KB Output is correct
26 Correct 226 ms 30200 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 32 ms 444 KB Output is correct
47 Correct 883 ms 29384 KB Output is correct
48 Correct 434 ms 30356 KB Output is correct
49 Correct 421 ms 30412 KB Output is correct
50 Correct 822 ms 28496 KB Output is correct
51 Correct 809 ms 28216 KB Output is correct
52 Correct 825 ms 28344 KB Output is correct
53 Correct 851 ms 30812 KB Output is correct
54 Correct 550 ms 724 KB Output is correct
55 Correct 560 ms 724 KB Output is correct
56 Correct 564 ms 724 KB Output is correct
57 Correct 568 ms 724 KB Output is correct
58 Correct 584 ms 724 KB Output is correct
59 Execution timed out 4051 ms 28788 KB Time limit exceeded
60 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 32 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Execution timed out 4091 ms 24916 KB Time limit exceeded
6 Halted 0 ms 0 KB -