結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー KKT89
提出日時 2021-01-23 02:44:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,085 bytes
コンパイル時間 1,807 ms
コンパイル使用メモリ 199,080 KB
最終ジャッジ日時 2025-01-18 07:11:46
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<vector<ll>> b(n,vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> b[i][j];
        }
    }
    ll res=-1;
    int id=0;
    for(int i=1;i<(1<<n);i++){
        ll sum=0;
        for(int j=0;j<n;j++){
            if((1<<j)&i){
                sum+=a[j];
                for(int k=j+1;k<n;k++){
                    if((1<<k)&i){
                        sum+=b[j][k];
                    }
                }
            }
        }
        if(sum>res){
            res=sum;
            id=i;
        }
    }
    cout << res << endl;
    for(int i=0;i<n;i++){
        if((1<<i)&id){
            cout << i+1 << " ";
        }
    }
    cout << endl;
}
0