結果

問題 No.519 アイドルユニット
コンテスト
ユーザー siman
提出日時 2022-03-04 18:37:40
言語 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  
実行時間 601 ms / 1,000 ms
コード長 914 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,690 ms
コンパイル使用メモリ 149,760 KB
実行使用メモリ 218,896 KB
最終ジャッジ日時 2026-04-02 09:52:51
合計ジャッジ時間 8,613 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:21:12: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   int V[N][N];
      |            ^
main.cpp:21:12: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
main.cpp:21:9: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   21 |   int V[N][N];
      |         ^
main.cpp:21:9: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:19:7: note: declared here
   19 |   int N;
      |       ^
2 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 dp[1 << 24];

int main() {
  int N;
  cin >> N;
  int V[N][N];

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

  int L = 1 << N;
  memset(dp, 0, sizeof(dp));
  int ans = 0;

  for (int mask = 0; mask < L; ++mask) {
    ans = max(ans, dp[mask]);
    if (__builtin_popcount(mask) & 1) continue;

    for (int j = 0; j < N; ++j) {
      if (mask >> j & 1) continue;
      for (int k = j + 1; k < N; ++k) {
        if (mask >> k & 1) continue;
        int nmask = mask | (1 << j) | (1 << k);
        dp[nmask] = max(dp[nmask], dp[mask] + V[j][k]);
      }
      break;
    }
  }

  cout << ans << endl;

  return 0;
}
0