結果

問題 No.1560 majority x majority
ユーザー noya2noya2
提出日時 2021-03-31 00:10:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 2,083 bytes
コンパイル時間 4,733 ms
コンパイル使用メモリ 271,692 KB
実行使用メモリ 6,876 KB
最終ジャッジ日時 2023-09-07 13:52:47
合計ジャッジ時間 7,292 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
6,876 KB
testcase_01 AC 43 ms
6,868 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 41 ms
6,860 KB
testcase_04 AC 38 ms
6,788 KB
testcase_05 AC 37 ms
6,788 KB
testcase_06 AC 11 ms
6,560 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 22 ms
5,288 KB
testcase_09 AC 14 ms
6,512 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 5 ms
4,384 KB
testcase_12 AC 3 ms
4,384 KB
testcase_13 AC 5 ms
4,384 KB
testcase_14 AC 4 ms
4,384 KB
testcase_15 AC 12 ms
6,456 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 22 ms
5,232 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 12 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 11 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using namespace atcoder;
using namespace internal;
using ll = long long;
using P = pair<int, int>;

template <typename SE>
void rev(vector<SE> &ar){reverse(ar.begin(),ar.end());}

const int maxsize = 5000;
using pbv = pair<bitset<maxsize>,vector<int>>;
typedef bitset<maxsize> bset;

int popcount(bset &a, int n){
    int ans = 0;
    rep(i,n) if(a.test(i)) ans++;
    return ans;
}

int ten(vector<int> &a, int m){
    rev(a);
    int ans = 0;
    rep(i,m){
        ans += a[i];
        if (i != m-1) ans *= 2;
    }
    return ans;
}

struct vs{
    vector<int> to;
    vector<int> from;
    int cases;
};

int main(){
    bset bm(0);
    bm.set();
    int n, m; cin >> n >> m;
    int rui = 1<<m;
    vector<vector<int>> ar(n,vector<int>(m));
    rep(i,n) rep(j,m) cin >> ar[i][j];
    vector<bset> b(m,0);
    rep(i,m){
        rep(j,n){
            if (ar[j][i] == 1) b[i].set(j);
        }
    }
    vector<int> popc(rui);
    queue<pbv> que;
    que.push(pbv(bm,{}));
    while (!que.empty()){
        pbv p = que.front(); que.pop();
        bset x = p.first;
        vector<int> c = p.second;
        int s = c.size();
        if (s == m){
            int pos = ten(c,m);
            int cnt = popcount(x,n);
            popc[pos] = cnt;
        }
        else {
            c.emplace_back(0);
            que.push(pbv(x,c));
            c[s] = 1;
            x &= b[s];
            que.push(pbv(x,c));
        }
    }
    vector<vs> dp(rui);
    rep(i,rui) dp[i].cases = 0;
    rep(i,rui){
        rep(j,m){
            if (~i >> j & 1){
                int t = i|1<<j;
                if (popc[t] * 2 < popc[i]) continue;
                dp[i].to.emplace_back(t);
                dp[t].from.emplace_back(i);
            }
        }
    }
    dp[0].cases = 1;
    repp(i,rui,1){
        for (int x : dp[i].from){
            dp[i].cases += dp[x].cases;
        }
    }
    cout << dp[rui-1].cases << endl;
}
0