結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー kyo1
提出日時 2021-01-24 11:17:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,044 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 199,256 KB
最終ジャッジ日時 2025-01-18 07:46:28
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto &&e : A) {
    cin >> e;
  }
  vector<vector<int64_t>> B(N, vector<int64_t>(N));
  for (auto &&e : B) {
    for (auto &&f : e) {
      cin >> f;
    }
  }
  pair<int, int64_t> res = make_pair(0, -(INT64_C(1) << 50));
  for (int b = 1; b < (1 << N); b++) {
    int64_t r = 0;
    for (int i = 0; i < N; i++) {
      if ((b >> i) & 1) {
        r += A[i];
        for (int j = i + 1; j < N; j++) {
          if ((b >> j) & 1) r += B[i][j];
        }
      }
    }
    if (chmax(res.second, r)) {
      res.first = b;
    }
  }
  cout << res.second << '\n';
  vector<int> J;
  for (int i = 0; i < N; i++) {
    if ((res.first >> i) & 1) J.emplace_back(i);
  }
  for (const auto &e : J) {
    cout << e + 1 << (&e == &J.back() ? '\n' : ' ');
  }
  return 0;
}
0