結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー mmn15277198mmn15277198
提出日時 2021-01-26 21:39:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,049 bytes
コンパイル時間 1,842 ms
コンパイル使用メモリ 174,364 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 19:49:44
合計ジャッジ時間 6,388 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 WA * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const ld pi = 3.14159265358979;
const int mod = 1000000007;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<vector<int>> b(n , vector<int>(n));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> b[i][j];
		}
	}
	ll ans = 0;
	vector<int>ans_bit;
	for(int i = 0; i < (1 << n); i++){
		ll cost = 0;
		vector<int> now;
		for(int j = 0; j < n; j++){
			if(i & (1 << j)){
				cost += (ll)a[j];
				now.push_back(j);
				//cout << 1 << " ";
			}else{
				//cout << 0 << " ";
			}
		}
		
		if(now.size() >= 2){
			for(int x = 0; x < now.size() - 1; x++){
				for(int y = x + 1; y < now.size(); y++){
					cost += (ll)b[x][y];
				}
			}
		}
		
		if(cost > ans){
			ans = cost;
			ans_bit = now;
		}
	}
	cout << ans << endl;
	
	for(int i = 0; i < ans_bit.size(); i++){
		cout << ans_bit[i] + 1;
		if(i != ans_bit.size() - 1){
			cout << " ";
		}else{
			cout << endl;
		}
	}
	return 0;
}
0