結果

問題 No.1560 majority x majority
コンテスト
ユーザー siman
提出日時 2022-07-18 14:10:22
言語 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  
実行時間 79 ms / 2,000 ms
コード長 1,132 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,445 ms
コンパイル使用メモリ 147,456 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-03-20 14:45:43
合計ジャッジ時間 8,421 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   int SM[N];
      |          ^
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:21:13: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   bool S[N][M];
      |             ^
main.cpp:21: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:21:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   bool S[N][M];
      |          ^
main.cpp:21: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:34:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   34 |   ll dp[L];
      |         ^
main.cpp:34:9: note: read of non-const variable 'L' is not allowed in a constant expression
main.cpp:33:7: note: declared here
   33 |   int L = 1 << M;
      |       ^
4 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;

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

  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) {
        if ((mask & SM[j]) != mask) 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