답안 #891880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
891880 2023-12-24T10:35:51 Z alexander707070 Council (JOI23_council) C++14
41 / 100
4000 ms 353636 KB
#include<bits/stdc++.h>
#define MAXN 300007
using namespace std;

struct sol{
    int ans1,t1;
    int ans2,t2;
}best;

int n,m,br[25],curr;
int a[MAXN],s[MAXN][25],res,ans;

sol ff2(int mask){
    sol res={0,0,0,0};
   
    for(int i=1;i<=n;i++){
        if((a[i]&mask)==0 and res.t1==0){
            res.ans1=__builtin_popcount(mask);
            res.t1=i;
        }else if((a[i]&mask)==0 and res.t2==0){
            res.ans2=__builtin_popcount(mask);
            res.t2=i;
        }
    }

    return res;
}

sol dp[25][1024*1024];
bool li[25][1024*1024];

sol ff(int n,int mask){
    if(n==-1)return ff2(mask);

    if(li[n][mask])return dp[n][mask];
    li[n][mask]=true;

    if((mask&(1<<n))==0){
        dp[n][mask]=ff(n-1,mask);
    }else{
        sol fr=ff(n-1,mask),sc=ff(n-1,mask^(1<<n));

        vector< pair<int,int> > w={{fr.ans1,fr.t1},{fr.ans2,fr.t2},{sc.ans1,sc.t1},{sc.ans2,sc.t2}};
        sort(w.begin(),w.end());
        reverse(w.begin(),w.end());

        dp[n][mask].ans1=w[0].first;
        dp[n][mask].t1=w[0].second;

        for(int i=1;i<w.size();i++){
            if(w[i].second==w[0].second)continue;  
            dp[n][mask].ans2=w[i].first; 
            dp[n][mask].t2=w[i].second;
            break;  
        }
    }

    return dp[n][mask];
}

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 f=1;f<=m;f++){
            cin>>s[i][f];
            a[i]*=2; a[i]+=s[i][f];

            br[f]+=s[i][f];
        }
    }

    for(int i=1;i<=n;i++){
        for(int f=1;f<=m;f++)br[f]-=s[i][f];
        
        curr=res=0;
        for(int f=1;f<=m;f++){
            curr*=2;
            if(br[f]==n/2)curr++;
            if(br[f]>n/2)res++;
        }

        best=ff(m-1,curr);

        if(best.t1!=i){
            ans=res+best.ans1;
        }else{
            ans=res+best.ans2;
        }

        cout<<ans<<"\n";

        for(int f=1;f<=m;f++)br[f]+=s[i][f];
    }

    return 0;
}

Compilation message

council.cpp: In function 'sol ff(int, int)':
council.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int i=1;i<w.size();i++){
      |                     ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 3 ms 27224 KB Output is correct
3 Correct 1 ms 10708 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 204 ms 335920 KB Output is correct
6 Correct 6 ms 43608 KB Output is correct
7 Correct 17 ms 167516 KB Output is correct
8 Correct 25 ms 248828 KB Output is correct
9 Correct 9 ms 84828 KB Output is correct
10 Correct 37 ms 329492 KB Output is correct
11 Correct 50 ms 343736 KB Output is correct
12 Correct 195 ms 352596 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6628 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 3 ms 22872 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 12796 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 16732 KB Output is correct
28 Correct 2 ms 18780 KB Output is correct
29 Correct 3 ms 20824 KB Output is correct
30 Correct 3 ms 22876 KB Output is correct
31 Correct 3 ms 22876 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 10588 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 2 ms 18780 KB Output is correct
38 Correct 2 ms 20828 KB Output is correct
39 Correct 3 ms 22876 KB Output is correct
40 Correct 4 ms 22880 KB Output is correct
41 Correct 6 ms 31424 KB Output is correct
42 Correct 3 ms 31324 KB Output is correct
43 Correct 4 ms 31324 KB Output is correct
44 Correct 4 ms 31324 KB Output is correct
45 Correct 4 ms 31324 KB Output is correct
46 Correct 27 ms 74144 KB Output is correct
47 Correct 5 ms 38236 KB Output is correct
48 Correct 5 ms 38492 KB Output is correct
49 Correct 12 ms 74076 KB Output is correct
50 Correct 11 ms 74252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 3 ms 27224 KB Output is correct
3 Correct 1 ms 10708 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 204 ms 335920 KB Output is correct
6 Correct 6 ms 43608 KB Output is correct
7 Correct 17 ms 167516 KB Output is correct
8 Correct 25 ms 248828 KB Output is correct
9 Correct 9 ms 84828 KB Output is correct
10 Correct 37 ms 329492 KB Output is correct
11 Correct 50 ms 343736 KB Output is correct
12 Correct 195 ms 352596 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6628 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 3 ms 22872 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 12796 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 16732 KB Output is correct
28 Correct 2 ms 18780 KB Output is correct
29 Correct 3 ms 20824 KB Output is correct
30 Correct 3 ms 22876 KB Output is correct
31 Correct 3 ms 22876 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 10588 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 2 ms 18780 KB Output is correct
38 Correct 2 ms 20828 KB Output is correct
39 Correct 3 ms 22876 KB Output is correct
40 Correct 4 ms 22880 KB Output is correct
41 Correct 6 ms 31424 KB Output is correct
42 Correct 3 ms 31324 KB Output is correct
43 Correct 4 ms 31324 KB Output is correct
44 Correct 4 ms 31324 KB Output is correct
45 Correct 4 ms 31324 KB Output is correct
46 Correct 27 ms 74144 KB Output is correct
47 Correct 5 ms 38236 KB Output is correct
48 Correct 5 ms 38492 KB Output is correct
49 Correct 12 ms 74076 KB Output is correct
50 Correct 11 ms 74252 KB Output is correct
51 Correct 9 ms 43612 KB Output is correct
52 Correct 8 ms 43796 KB Output is correct
53 Correct 8 ms 43612 KB Output is correct
54 Correct 2089 ms 353636 KB Output is correct
55 Correct 2 ms 6488 KB Output is correct
56 Correct 345 ms 74656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 45 ms 37644 KB Output is correct
3 Correct 53 ms 37672 KB Output is correct
4 Correct 39 ms 34892 KB Output is correct
5 Correct 48 ms 37456 KB Output is correct
6 Correct 36 ms 35036 KB Output is correct
7 Correct 56 ms 37612 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 45 ms 37644 KB Output is correct
3 Correct 53 ms 37672 KB Output is correct
4 Correct 39 ms 34892 KB Output is correct
5 Correct 48 ms 37456 KB Output is correct
6 Correct 36 ms 35036 KB Output is correct
7 Correct 56 ms 37612 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 529 ms 58684 KB Output is correct
21 Correct 344 ms 56044 KB Output is correct
22 Correct 340 ms 56148 KB Output is correct
23 Correct 159 ms 59000 KB Output is correct
24 Correct 140 ms 58812 KB Output is correct
25 Correct 155 ms 58852 KB Output is correct
26 Correct 627 ms 58892 KB Output is correct
27 Correct 3 ms 22872 KB Output is correct
28 Correct 1 ms 8536 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 12636 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 16728 KB Output is correct
33 Correct 2 ms 18780 KB Output is correct
34 Correct 3 ms 20828 KB Output is correct
35 Correct 3 ms 22876 KB Output is correct
36 Correct 3 ms 22876 KB Output is correct
37 Correct 1 ms 8660 KB Output is correct
38 Correct 1 ms 10588 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 14684 KB Output is correct
41 Correct 2 ms 16732 KB Output is correct
42 Correct 2 ms 18780 KB Output is correct
43 Correct 3 ms 20828 KB Output is correct
44 Correct 3 ms 22996 KB Output is correct
45 Correct 4 ms 22872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 45 ms 37644 KB Output is correct
3 Correct 53 ms 37672 KB Output is correct
4 Correct 39 ms 34892 KB Output is correct
5 Correct 48 ms 37456 KB Output is correct
6 Correct 36 ms 35036 KB Output is correct
7 Correct 56 ms 37612 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 529 ms 58684 KB Output is correct
21 Correct 344 ms 56044 KB Output is correct
22 Correct 340 ms 56148 KB Output is correct
23 Correct 159 ms 59000 KB Output is correct
24 Correct 140 ms 58812 KB Output is correct
25 Correct 155 ms 58852 KB Output is correct
26 Correct 627 ms 58892 KB Output is correct
27 Correct 3 ms 22872 KB Output is correct
28 Correct 1 ms 8536 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 12636 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 16728 KB Output is correct
33 Correct 2 ms 18780 KB Output is correct
34 Correct 3 ms 20828 KB Output is correct
35 Correct 3 ms 22876 KB Output is correct
36 Correct 3 ms 22876 KB Output is correct
37 Correct 1 ms 8660 KB Output is correct
38 Correct 1 ms 10588 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 14684 KB Output is correct
41 Correct 2 ms 16732 KB Output is correct
42 Correct 2 ms 18780 KB Output is correct
43 Correct 3 ms 20828 KB Output is correct
44 Correct 3 ms 22996 KB Output is correct
45 Correct 4 ms 22872 KB Output is correct
46 Correct 4 ms 27228 KB Output is correct
47 Correct 3823 ms 69508 KB Output is correct
48 Correct 2111 ms 67056 KB Output is correct
49 Correct 2067 ms 66900 KB Output is correct
50 Correct 217 ms 69712 KB Output is correct
51 Correct 198 ms 69364 KB Output is correct
52 Correct 207 ms 69204 KB Output is correct
53 Execution timed out 4022 ms 69064 KB Time limit exceeded
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 45 ms 37644 KB Output is correct
3 Correct 53 ms 37672 KB Output is correct
4 Correct 39 ms 34892 KB Output is correct
5 Correct 48 ms 37456 KB Output is correct
6 Correct 36 ms 35036 KB Output is correct
7 Correct 56 ms 37612 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6488 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 8536 KB Output is correct
19 Correct 1 ms 10588 KB Output is correct
20 Correct 529 ms 58684 KB Output is correct
21 Correct 344 ms 56044 KB Output is correct
22 Correct 340 ms 56148 KB Output is correct
23 Correct 159 ms 59000 KB Output is correct
24 Correct 140 ms 58812 KB Output is correct
25 Correct 155 ms 58852 KB Output is correct
26 Correct 627 ms 58892 KB Output is correct
27 Correct 3 ms 22872 KB Output is correct
28 Correct 1 ms 8536 KB Output is correct
29 Correct 2 ms 10588 KB Output is correct
30 Correct 2 ms 12636 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 16728 KB Output is correct
33 Correct 2 ms 18780 KB Output is correct
34 Correct 3 ms 20828 KB Output is correct
35 Correct 3 ms 22876 KB Output is correct
36 Correct 3 ms 22876 KB Output is correct
37 Correct 1 ms 8660 KB Output is correct
38 Correct 1 ms 10588 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 14684 KB Output is correct
41 Correct 2 ms 16732 KB Output is correct
42 Correct 2 ms 18780 KB Output is correct
43 Correct 3 ms 20828 KB Output is correct
44 Correct 3 ms 22996 KB Output is correct
45 Correct 4 ms 22872 KB Output is correct
46 Correct 4 ms 27228 KB Output is correct
47 Correct 3823 ms 69508 KB Output is correct
48 Correct 2111 ms 67056 KB Output is correct
49 Correct 2067 ms 66900 KB Output is correct
50 Correct 217 ms 69712 KB Output is correct
51 Correct 198 ms 69364 KB Output is correct
52 Correct 207 ms 69204 KB Output is correct
53 Execution timed out 4022 ms 69064 KB Time limit exceeded
54 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 3 ms 27224 KB Output is correct
3 Correct 1 ms 10708 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 204 ms 335920 KB Output is correct
6 Correct 6 ms 43608 KB Output is correct
7 Correct 17 ms 167516 KB Output is correct
8 Correct 25 ms 248828 KB Output is correct
9 Correct 9 ms 84828 KB Output is correct
10 Correct 37 ms 329492 KB Output is correct
11 Correct 50 ms 343736 KB Output is correct
12 Correct 195 ms 352596 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 6628 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 3 ms 22872 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 2 ms 10844 KB Output is correct
25 Correct 2 ms 12796 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 16732 KB Output is correct
28 Correct 2 ms 18780 KB Output is correct
29 Correct 3 ms 20824 KB Output is correct
30 Correct 3 ms 22876 KB Output is correct
31 Correct 3 ms 22876 KB Output is correct
32 Correct 1 ms 8540 KB Output is correct
33 Correct 1 ms 10588 KB Output is correct
34 Correct 2 ms 12636 KB Output is correct
35 Correct 2 ms 14684 KB Output is correct
36 Correct 2 ms 16732 KB Output is correct
37 Correct 2 ms 18780 KB Output is correct
38 Correct 2 ms 20828 KB Output is correct
39 Correct 3 ms 22876 KB Output is correct
40 Correct 4 ms 22880 KB Output is correct
41 Correct 6 ms 31424 KB Output is correct
42 Correct 3 ms 31324 KB Output is correct
43 Correct 4 ms 31324 KB Output is correct
44 Correct 4 ms 31324 KB Output is correct
45 Correct 4 ms 31324 KB Output is correct
46 Correct 27 ms 74144 KB Output is correct
47 Correct 5 ms 38236 KB Output is correct
48 Correct 5 ms 38492 KB Output is correct
49 Correct 12 ms 74076 KB Output is correct
50 Correct 11 ms 74252 KB Output is correct
51 Correct 9 ms 43612 KB Output is correct
52 Correct 8 ms 43796 KB Output is correct
53 Correct 8 ms 43612 KB Output is correct
54 Correct 2089 ms 353636 KB Output is correct
55 Correct 2 ms 6488 KB Output is correct
56 Correct 345 ms 74656 KB Output is correct
57 Correct 1 ms 6488 KB Output is correct
58 Correct 45 ms 37644 KB Output is correct
59 Correct 53 ms 37672 KB Output is correct
60 Correct 39 ms 34892 KB Output is correct
61 Correct 48 ms 37456 KB Output is correct
62 Correct 36 ms 35036 KB Output is correct
63 Correct 56 ms 37612 KB Output is correct
64 Correct 1 ms 4440 KB Output is correct
65 Correct 1 ms 4440 KB Output is correct
66 Correct 1 ms 6492 KB Output is correct
67 Correct 1 ms 6488 KB Output is correct
68 Correct 1 ms 6492 KB Output is correct
69 Correct 1 ms 4444 KB Output is correct
70 Correct 1 ms 6492 KB Output is correct
71 Correct 1 ms 6492 KB Output is correct
72 Correct 1 ms 6492 KB Output is correct
73 Correct 1 ms 6492 KB Output is correct
74 Correct 1 ms 8536 KB Output is correct
75 Correct 1 ms 10588 KB Output is correct
76 Correct 529 ms 58684 KB Output is correct
77 Correct 344 ms 56044 KB Output is correct
78 Correct 340 ms 56148 KB Output is correct
79 Correct 159 ms 59000 KB Output is correct
80 Correct 140 ms 58812 KB Output is correct
81 Correct 155 ms 58852 KB Output is correct
82 Correct 627 ms 58892 KB Output is correct
83 Correct 3 ms 22872 KB Output is correct
84 Correct 1 ms 8536 KB Output is correct
85 Correct 2 ms 10588 KB Output is correct
86 Correct 2 ms 12636 KB Output is correct
87 Correct 2 ms 14684 KB Output is correct
88 Correct 2 ms 16728 KB Output is correct
89 Correct 2 ms 18780 KB Output is correct
90 Correct 3 ms 20828 KB Output is correct
91 Correct 3 ms 22876 KB Output is correct
92 Correct 3 ms 22876 KB Output is correct
93 Correct 1 ms 8660 KB Output is correct
94 Correct 1 ms 10588 KB Output is correct
95 Correct 2 ms 12632 KB Output is correct
96 Correct 2 ms 14684 KB Output is correct
97 Correct 2 ms 16732 KB Output is correct
98 Correct 2 ms 18780 KB Output is correct
99 Correct 3 ms 20828 KB Output is correct
100 Correct 3 ms 22996 KB Output is correct
101 Correct 4 ms 22872 KB Output is correct
102 Correct 4 ms 27228 KB Output is correct
103 Correct 3823 ms 69508 KB Output is correct
104 Correct 2111 ms 67056 KB Output is correct
105 Correct 2067 ms 66900 KB Output is correct
106 Correct 217 ms 69712 KB Output is correct
107 Correct 198 ms 69364 KB Output is correct
108 Correct 207 ms 69204 KB Output is correct
109 Execution timed out 4022 ms 69064 KB Time limit exceeded
110 Halted 0 ms 0 KB -