結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー soto800soto800
提出日時 2021-01-22 21:25:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,779 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 171,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 17:15:36
合計ジャッジ時間 7,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 8 ms
4,376 KB
testcase_24 AC 16 ms
4,384 KB
testcase_25 AC 60 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 63 ms
4,376 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 8 ms
4,380 KB
testcase_31 AC 8 ms
4,380 KB
testcase_32 AC 3 ms
4,380 KB
testcase_33 AC 61 ms
4,380 KB
testcase_34 AC 60 ms
4,376 KB
testcase_35 AC 61 ms
4,376 KB
testcase_36 AC 62 ms
4,380 KB
testcase_37 AC 62 ms
4,384 KB
testcase_38 AC 65 ms
4,380 KB
testcase_39 AC 62 ms
4,380 KB
testcase_40 AC 60 ms
4,380 KB
testcase_41 AC 62 ms
4,376 KB
testcase_42 AC 66 ms
4,376 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 63 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 61 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<28)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define MOD (1000000007)
#define TO_STRING(VariableName) # VariableName
#define LOG(xx) if(DEBUG)cout<<TO_STRING(xx)<<"="<<xx<<" "<<endl;
#define LOG2(xx,yy) if(DEBUG)cout<<TO_STRING(xx)<<"="<<xx<<" "<<TO_STRING(yy)<<"="<<yy<<endl;
#define LOG3(xx,yy,z) if(DEBUG)cout<<TO_STRING(xx)<<"="<<xx<<" "<<TO_STRING(yy)<<"="<<yy<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,xx,yy,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(xx)<<"="<<xx<<" "<<TO_STRING(yy)<<"="<<yy<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

lli dd[20][20];

lli b[20][20];

int main(){

    lli n;
    cin>>n;
    vector<lli> a(n);
    REP(i,0,n)cin>>a[i];

    REP(i,0,n)REP(j,0,n)cin>>b[i][j];

    lli ans = 0;
    vector<lli> ansV;
    for(lli i=0;i<(1LL<<n);i++){
        vector<lli> c;
        lli score = 0;
        for(lli j=0;j<n;j++){
            if(i&(1LL<<j)){
                score += a[j];
                c.push_back(j);
            }
        }
        for(lli x = 0;x<c.size();x++){
            for(lli y=x+1;y<c.size();y++){
                score += b[c[x]][c[y]];
            }
        }
        if(score >= ans){
            ans = score;
            ansV = c;
        }
    }
    cout<<ans<<endl;
    REP(i,0,ansV.size()){
        cout<<ansV[i]+1;
        if(i!=ansV.size()-1)cout<<" ";
        else cout<<endl;
    }


    return 0;
}
0