Submission #793174

# Submission time Handle Problem Language Result Execution time Memory
793174 2023-07-25T15:09:15 Z Cookie Council (JOI23_council) C++14
22 / 100
102 ms 29232 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("FEEDING.INP");
ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7, inf = 1e9;
const int mxn = 1e5 + 5;
int n, m;
pii son[(1 << 20)];
char c[300005][21];
int cnt[(1 << 20)], val[20], mask[300005];
pair<pii, pii>dp[(1 << 20)];
bool ckmx(pii a, pii b){
    if(b.fi == 0)return(1);
    return(a.se > b.se);
}
signed 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++){
            cin >> c[i][j];
            if(c[i][j] == '1'){
                mask[i] += (1 << j);
                val[j]++;
            }
        }
        mask[i] = (((1 << m) - 1) ^ mask[i]);
        if(!son[mask[i]].fi)son[mask[i]].fi = i;
        else if(!son[mask[i]].se)son[mask[i]].se = i;
    }
    for(int i = 0; i < (1 << m); i++){
        cnt[i] = __builtin_popcount(i);
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < (1 << m); j++){
            if(!(j & (1 << i))){
                int &x = son[j].fi, &y = son[j].se, candx = son[j ^ (1 << i)].fi, candy = son[j ^ (1 << i)].se;
                if(x){
                    if(!y){
                        if(candx && candx != x)y = candx;
                        else if(candy && candy != x)y = candy;
                    }
                }else{
                    if(candx){
                        x = candx;
                        if(candy)y = candy;
                    }else{
                        if(candy)x = candy;
                    }
                }
                
            }
        }
    }
    for(int i = 0; i < (1 << m); i++){
        
        dp[i] = make_pair(make_pair(son[i].first, ((son[i].first ? cnt[i] : 0))), make_pair(son[i].second, (son[i].second ? cnt[i] : 0)));
        
    }
    
    for(int i = 0; i < m; i++){
        for(int j = 0; j < (1 << m); j++){
            if(j & (1 << i)){
                auto [cand1, cand2] = dp[j ^ (1 << i)];
                
                if(cand1.fi && ckmx(cand1, dp[j].se)){
                    
                    dp[j].se = cand1;
                    
                    if(ckmx(dp[j].se, dp[j].fi)){
                        
                        swap(dp[j].fi, dp[j].se);
                    }
                    if(dp[j].fi.fi == dp[j].se.fi){
                        dp[j].se = make_pair(0, 0);
                    }
                }if(cand2.fi && ckmx(cand2, dp[j].se)){
                    
                    dp[j].se = cand2;
                    if(ckmx(dp[j].se, dp[j].fi)){
                        swap(dp[j].fi, dp[j].se);
                    }
                    if(dp[j].fi.fi == dp[j].se.fi){
                        dp[j].se = make_pair(0, 0);
                    }
                }
            }
        }
    }
    
    for(int i = 1; i <= n; i++){
        int mask = 0, ans = 0;
        for(int j = 0; j < m; j++){
            if(c[i][j] == '1'){
                val[j]--; 
            }
            if(val[j] == n / 2){
                mask += (1 << j); ans++;
            }else if(val[j] > n / 2)ans++;
            if(c[i][j] == '1'){
                val[j]++;
            }
        }
        //cout << mask << " ";
        auto [res1, res2] = dp[mask];
        
        if(res1.fi != i){
            //cout << res1.se << " " << " " << cnt[mask] << " ";
            cout << ans - (cnt[mask] - res1.se) << "\n";
        }else{
            assert(res2.fi != i);
            cout << ans - (cnt[mask] - res2.se) << "\n";
        }
        
    }
    return(0);
}

Compilation message

council.cpp: In function 'int main()':
council.cpp:82:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |                 auto [cand1, cand2] = dp[j ^ (1 << i)];
      |                      ^
council.cpp:123:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  123 |         auto [res1, res2] = dp[mask];
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 65 ms 24976 KB Output is correct
6 Correct 59 ms 20868 KB Output is correct
7 Correct 64 ms 23372 KB Output is correct
8 Correct 72 ms 23368 KB Output is correct
9 Correct 102 ms 28660 KB Output is correct
10 Correct 66 ms 22696 KB Output is correct
11 Correct 72 ms 24720 KB Output is correct
12 Correct 85 ms 28532 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 732 KB Output is correct
46 Correct 7 ms 3408 KB Output is correct
47 Correct 10 ms 3360 KB Output is correct
48 Correct 8 ms 3540 KB Output is correct
49 Correct 7 ms 3284 KB Output is correct
50 Correct 8 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 65 ms 24976 KB Output is correct
6 Correct 59 ms 20868 KB Output is correct
7 Correct 64 ms 23372 KB Output is correct
8 Correct 72 ms 23368 KB Output is correct
9 Correct 102 ms 28660 KB Output is correct
10 Correct 66 ms 22696 KB Output is correct
11 Correct 72 ms 24720 KB Output is correct
12 Correct 85 ms 28532 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 732 KB Output is correct
46 Correct 7 ms 3408 KB Output is correct
47 Correct 10 ms 3360 KB Output is correct
48 Correct 8 ms 3540 KB Output is correct
49 Correct 7 ms 3284 KB Output is correct
50 Correct 8 ms 3924 KB Output is correct
51 Correct 76 ms 21060 KB Output is correct
52 Correct 67 ms 29140 KB Output is correct
53 Correct 85 ms 29196 KB Output is correct
54 Correct 90 ms 29232 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 12 ms 4124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 31 ms 8332 KB Output is correct
3 Correct 26 ms 8396 KB Output is correct
4 Correct 25 ms 8312 KB Output is correct
5 Correct 32 ms 8340 KB Output is correct
6 Correct 25 ms 8428 KB Output is correct
7 Correct 32 ms 8404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 31 ms 8332 KB Output is correct
3 Correct 26 ms 8396 KB Output is correct
4 Correct 25 ms 8312 KB Output is correct
5 Correct 32 ms 8340 KB Output is correct
6 Correct 25 ms 8428 KB Output is correct
7 Correct 32 ms 8404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 88 ms 8380 KB Output is correct
21 Incorrect 77 ms 8412 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 31 ms 8332 KB Output is correct
3 Correct 26 ms 8396 KB Output is correct
4 Correct 25 ms 8312 KB Output is correct
5 Correct 32 ms 8340 KB Output is correct
6 Correct 25 ms 8428 KB Output is correct
7 Correct 32 ms 8404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 88 ms 8380 KB Output is correct
21 Incorrect 77 ms 8412 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 31 ms 8332 KB Output is correct
3 Correct 26 ms 8396 KB Output is correct
4 Correct 25 ms 8312 KB Output is correct
5 Correct 32 ms 8340 KB Output is correct
6 Correct 25 ms 8428 KB Output is correct
7 Correct 32 ms 8404 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 344 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 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 88 ms 8380 KB Output is correct
21 Incorrect 77 ms 8412 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 65 ms 24976 KB Output is correct
6 Correct 59 ms 20868 KB Output is correct
7 Correct 64 ms 23372 KB Output is correct
8 Correct 72 ms 23368 KB Output is correct
9 Correct 102 ms 28660 KB Output is correct
10 Correct 66 ms 22696 KB Output is correct
11 Correct 72 ms 24720 KB Output is correct
12 Correct 85 ms 28532 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 724 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 1 ms 724 KB Output is correct
44 Correct 1 ms 724 KB Output is correct
45 Correct 1 ms 732 KB Output is correct
46 Correct 7 ms 3408 KB Output is correct
47 Correct 10 ms 3360 KB Output is correct
48 Correct 8 ms 3540 KB Output is correct
49 Correct 7 ms 3284 KB Output is correct
50 Correct 8 ms 3924 KB Output is correct
51 Correct 76 ms 21060 KB Output is correct
52 Correct 67 ms 29140 KB Output is correct
53 Correct 85 ms 29196 KB Output is correct
54 Correct 90 ms 29232 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 12 ms 4124 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 31 ms 8332 KB Output is correct
59 Correct 26 ms 8396 KB Output is correct
60 Correct 25 ms 8312 KB Output is correct
61 Correct 32 ms 8340 KB Output is correct
62 Correct 25 ms 8428 KB Output is correct
63 Correct 32 ms 8404 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 0 ms 344 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 88 ms 8380 KB Output is correct
77 Incorrect 77 ms 8412 KB Output isn't correct
78 Halted 0 ms 0 KB -