結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー 夜
提出日時 2021-01-23 09:30:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 2,999 ms
コンパイル使用メモリ 92,296 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-28 18:13:42
合計ジャッジ時間 9,478 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 13 ms
4,380 KB
testcase_24 AC 24 ms
4,504 KB
testcase_25 AC 98 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 99 ms
4,376 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 13 ms
4,380 KB
testcase_31 AC 13 ms
4,380 KB
testcase_32 AC 5 ms
4,380 KB
testcase_33 AC 99 ms
4,376 KB
testcase_34 AC 99 ms
4,380 KB
testcase_35 AC 98 ms
4,380 KB
testcase_36 AC 99 ms
4,380 KB
testcase_37 AC 99 ms
4,376 KB
testcase_38 AC 99 ms
4,376 KB
testcase_39 AC 99 ms
4,380 KB
testcase_40 AC 98 ms
4,376 KB
testcase_41 AC 99 ms
4,380 KB
testcase_42 AC 99 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 99 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 100 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:60:22: 警告: ‘ans1’ may be used uninitialized [-Wmaybe-uninitialized]
   60 |                 ans1 /= 2;
      |                 ~~~~~^~~~
main.cpp:30:35: 備考: ‘ans1’ はここで定義されています
   30 |         long ans = -100000000007, ans1;
      |                                   ^~~~

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long a[20], b[20][20];
bool bo[20];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> b[i][j];
		}
	}
	long ans = -100000000007, ans1;
	for (int i = 1; i < (1 << n); i++) {
		long score = 0;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				bo[j] = 1;
				score += a[j];
			}
			else {
				bo[j] = 0;
			}
		}
		for (int j = 0; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (bo[j] && bo[k]) {
					score += b[j][k];
				}
			}
		}
		if (ans < score) {
			ans = score;
			ans1 = i;
		}
	}
	cout << ans << endl;
	int co = 1;
	while (ans1 > 0) {
		if (ans1 % 2 == 1) {
			cout << co << " ";
		}
		ans1 /= 2;
		co++;
	}
	cout << endl;
}
0