結果
| 問題 | 
                            No.1360 [Zelkova 4th Tune] 協和音
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-01-23 09:30:26 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 120 ms / 2,000 ms | 
| コード長 | 1,045 bytes | 
| コンパイル時間 | 1,015 ms | 
| コンパイル使用メモリ | 94,760 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-30 02:29:51 | 
| 合計ジャッジ時間 | 6,788 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 47 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:60:22: warning: 'ans1' may be used uninitialized [-Wmaybe-uninitialized]
   60 |                 ans1 /= 2;
      |                 ~~~~~^~~~
main.cpp:30:35: note: 'ans1' was declared here
   30 |         long ans = -100000000007, ans1;
      |                                   ^~~~
            
            ソースコード
#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;
}