結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー yakkiyakki
提出日時 2021-01-22 22:08:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 1,116 ms
コンパイル使用メモリ 122,820 KB
最終ジャッジ日時 2025-01-18 04:26:24
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<ll>> b(n,vector<ll>(n));
    rep(i,n)rep(j,n) cin >> b[i][j];
    vector<int> ans2;
    ll ans = -LINF;
    repr(i,1,1<<n){
        vector<int> v;
        ll now = 0;
        rep(j,n){
            if(i>>j&1){
                v.push_back(j);
                now += a[j];
            }
        }
        int m = v.size();
        rep(j,m-1)repr(k,j+1,m){
            now += b[v[j]][v[k]];
        }
        if(ans < now){
            ans = now;
            ans2 = v;
        }
    }
    cout << ans << endl;
    rep(i,ans2.size()){
        cout << ans2[i]+1 << " "; 
    }
    cout << endl;
}



0