結果
問題 | No.1360 [Zelkova 4th Tune] 協和音 |
ユーザー |
|
提出日時 | 2021-01-22 21:36:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 165 ms / 2,000 ms |
コード長 | 752 bytes |
コンパイル時間 | 1,935 ms |
コンパイル使用メモリ | 208,012 KB |
最終ジャッジ日時 | 2025-01-18 03:53:27 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
#include<bits/stdc++.h>//#include<atcoder/all>//using namespace atcoder;using namespace std;using ll = long long;int main(){int n;cin >> n;vector<ll> a(n);vector<vector<ll>> b(n,vector<ll>(n));for(auto &i:a)cin >> i;for(auto &i:b)for(auto &j:i)cin >> j;vector<int> ansvec = {0};ll ans = a[0];for(int bit=0;bit<(1<<n);bit++){ll now = 0;set<int> st;for(int j = 0;j<n;j++){if(bit>>j&1){st.insert(j);now += a[j];}}vector<int> st2;for(auto &i:st)st2.push_back(i);for(int i = 0;i<st2.size();i++){for(int j = i+1;j<st2.size();j++){now += b[st2[i]][st2[j]];}}if(now>ans){ans = now;ansvec = st2;}}cout<<ans<<endl;for(auto &i:ansvec)cout<<i+1<<' ' ;cout<<endl;}