結果

問題 No.1560 majority x majority
コンテスト
ユーザー siman
提出日時 2022-07-18 14:05:12
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,060 ms / 2,000 ms
コード長 1,160 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,982 ms
コンパイル使用メモリ 147,584 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-20 14:27:37
合計ジャッジ時間 9,586 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   bool S[N][M];
      |             ^
main.cpp:20:13: note: read of non-const variable 'M' is not allowed in a constant expression
main.cpp:17:10: note: declared here
   17 |   int N, M;
      |          ^
main.cpp:20:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   bool S[N][M];
      |          ^
main.cpp:20:10: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N, M;
      |       ^
main.cpp:28:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   28 |   ll dp[L];
      |         ^
main.cpp:28:9: note: read of non-const variable 'L' is not allowed in a constant expression
main.cpp:27:7: note: declared here
   27 |   int L = 1 << M;
      |       ^
3 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  bool S[N][M];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> S[i][j];
    }
  }

  int L = 1 << M;
  ll dp[L];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;

  for (int mask = 0; mask < L; ++mask) {
    for (int i = 0; i < M; ++i) {
      if (mask >> i & 1) continue;

      int all = 0;
      int num = 0;

      for (int j = 0; j < N; ++j) {
        bool valid = true;
        for (int k = 0; k < M && valid; ++k) {
          if ((mask >> k & 1) && not S[j][k]) valid = false;
        }
        if (not valid) continue;

        if (S[j][i]) {
          ++num;
        }
        ++all;
      }

      int nmask = mask | (1 << i);
      // fprintf(stderr, "mask: %d, nmask: %d, (%d/%d)\n", mask, nmask, num, all);
      if (num >= (all + 1) / 2) {
        dp[nmask] += dp[mask];
      }
    }
  }

  cout << dp[L - 1] << endl;

  return 0;
}
0