Submission #1109472

# Submission time Handle Problem Language Result Execution time Memory
1109472 2024-11-06T19:23:18 Z vladilius Council (JOI23_council) C++17
6 / 100
1201 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n, m; cin>>n>>m;
    vector<vector<bool>> a(n + 1, vector<bool>(m + 1));
    vector<int> A[m + 1], B[n + 1];
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            bool b; cin>>b;
            if (b){
                A[j].pb(i);
                B[i].pb(j);
            }
            a[i][j] = b;
        }
    }
    
    vector<int> x(m + 1);
    for (int i = 1; i <= m; i++) x[i] = (int) A[i].size();
    
    vector<int> tw(m + 1); tw[0] = 1;
    for (int i = 1; i <= m; i++){
        tw[i] = tw[i - 1] * 2;
    }
    vector<int> F[tw[m]];
    vector<int> y(n + 1);
    function<void(int, int)> rec = [&](int i, int v){
        if (i == m + 1){
            F[v] = y;
            return;
        }
        rec(i + 1, v);
        for (int j: A[i]){
            y[j]++;
        }
        rec(i + 1, v + tw[i - 1]);
        for (int j: A[i]){
            y[j]--;
        }
    };
    rec(1, 0);
    
    vector<vector<int>> p1(tw[m], vector<int>(n + 1)), p2(tw[m], vector<int>(n + 2));
    for (int i = 0; i < tw[m]; i++){
        p1[i][0] = 1e9;
        for (int j = 1; j <= n; j++){
            p1[i][j] = min(p1[i][j - 1], F[i][j]);
        }
        p2[i][n + 1] = 1e9;
        for (int j = n; j > 0; j--){
            p2[i][j] = min(p2[i][j + 1], F[i][j]);
        }
    }
    
    const int M = n / 2;
    vector<int> all;
    
    for (int i = 1; i <= n; i++){
        for (int j: B[i]) x[j]--;
        
        all.clear();
        int f = m;
        for (int j = 1; j <= m; j++){
            if (x[j] != M){
                f -= (x[j] < M);
                continue;
            }
            all.pb(j);
        }
        
        int v = 0;
        for (int j: all){
            v += tw[j - 1];
        }
        
        cout<<f - min(p1[v][i - 1], p2[v][i + 1])<<"\n";

        for (int j: B[i]) x[j]++;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 1048 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1016 ms 616008 KB Output is correct
6 Runtime error 1201 ms 1048576 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 1048 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1016 ms 616008 KB Output is correct
6 Runtime error 1201 ms 1048576 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 114 ms 60352 KB Output is correct
3 Correct 78 ms 46656 KB Output is correct
4 Correct 80 ms 44584 KB Output is correct
5 Correct 96 ms 54920 KB Output is correct
6 Correct 73 ms 44328 KB Output is correct
7 Correct 98 ms 54940 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 114 ms 60352 KB Output is correct
3 Correct 78 ms 46656 KB Output is correct
4 Correct 80 ms 44584 KB Output is correct
5 Correct 96 ms 54920 KB Output is correct
6 Correct 73 ms 44328 KB Output is correct
7 Correct 98 ms 54940 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Runtime error 1065 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 114 ms 60352 KB Output is correct
3 Correct 78 ms 46656 KB Output is correct
4 Correct 80 ms 44584 KB Output is correct
5 Correct 96 ms 54920 KB Output is correct
6 Correct 73 ms 44328 KB Output is correct
7 Correct 98 ms 54940 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Runtime error 1065 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 114 ms 60352 KB Output is correct
3 Correct 78 ms 46656 KB Output is correct
4 Correct 80 ms 44584 KB Output is correct
5 Correct 96 ms 54920 KB Output is correct
6 Correct 73 ms 44328 KB Output is correct
7 Correct 98 ms 54940 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 2 ms 848 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Runtime error 1065 ms 1048576 KB Execution killed with signal 9
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 1048 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1016 ms 616008 KB Output is correct
6 Runtime error 1201 ms 1048576 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -