結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー tnakao0123tnakao0123
提出日時 2021-01-25 17:21:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 913 ms
コンパイル使用メモリ 91,824 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-04 10:24:05
合計ジャッジ時間 8,612 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 7 ms
4,384 KB
testcase_24 AC 14 ms
4,380 KB
testcase_25 AC 55 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 55 ms
4,380 KB
testcase_29 AC 5 ms
4,384 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 7 ms
4,384 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 57 ms
4,384 KB
testcase_34 AC 56 ms
4,380 KB
testcase_35 AC 56 ms
4,380 KB
testcase_36 AC 55 ms
4,380 KB
testcase_37 AC 55 ms
4,384 KB
testcase_38 AC 55 ms
4,380 KB
testcase_39 AC 55 ms
4,388 KB
testcase_40 AC 55 ms
4,384 KB
testcase_41 AC 56 ms
4,384 KB
testcase_42 AC 55 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 55 ms
4,384 KB
testcase_45 AC 2 ms
4,384 KB
testcase_46 AC 55 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1360.cc:  No.1360 [Zelkova 4th Tune] 協和音 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 18;
const int NBITS = 1 << MAX_N;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N], bs[MAX_N][MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) scanf("%d", as + i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) scanf("%d", bs[i] + j);

  int nbits = 1 << n, maxbits = 0;
  ll maxsum = -LINF;

  for (int bits = 1; bits < nbits; bits++) {
    ll sum = 0;
    for (int i = 0, bi = 1; i < n; i++, bi <<= 1)
      if (bits & bi) {
	sum += as[i];
	for (int j = i + 1, bj = 1 << j; j < n; j++, bj <<= 1)
	  if (bits & bj) sum += bs[i][j];
      }

    if (maxsum < sum) maxsum = sum, maxbits = bits;
  }

  printf("%lld\n", maxsum);
  for (int i = 0, bi = 1, cont = 0; i < n; i++, bi <<= 1)
    if (maxbits & bi) {
      if (cont) putchar(' ');
      printf("%d", i + 1);
      cont = 1;
    }
  putchar('\n');
  return 0;
}
0