結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー umezoumezo
提出日時 2021-01-22 22:36:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 203,080 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 20:34:52
合計ジャッジ時間 10,229 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 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 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 14 ms
4,376 KB
testcase_24 AC 27 ms
4,376 KB
testcase_25 AC 118 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 119 ms
4,376 KB
testcase_29 AC 7 ms
4,384 KB
testcase_30 AC 14 ms
4,380 KB
testcase_31 AC 14 ms
4,380 KB
testcase_32 AC 4 ms
4,384 KB
testcase_33 AC 118 ms
4,384 KB
testcase_34 AC 119 ms
4,376 KB
testcase_35 AC 119 ms
4,380 KB
testcase_36 AC 120 ms
4,380 KB
testcase_37 AC 121 ms
4,376 KB
testcase_38 AC 119 ms
4,376 KB
testcase_39 AC 119 ms
4,376 KB
testcase_40 AC 119 ms
4,376 KB
testcase_41 AC 119 ms
4,380 KB
testcase_42 AC 119 ms
4,380 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 AC 119 ms
4,384 KB
testcase_45 AC 1 ms
4,384 KB
testcase_46 AC 118 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:45:12: 警告: ‘ans2’ may be used uninitialized [-Wmaybe-uninitialized]
   45 |     if(ans2&(1<<i)){
      |        ~~~~^~~~~~~
main.cpp:23:6: 備考: ‘ans2’ はここで定義されています
   23 |   ll ans2;
      |      ^~~~

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

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

const ll INF=2e18;

int main(){
  int n;
  cin>>n;
  
  vector<ll> A(n);
  vector<vector<ll>> B(n,vector<ll> (n));
  
  rep(i,n) cin>>A[i];
  rep(i,n){
    rep(j,n) cin>>B[i][j];
  }
  
  ll ans=-INF;
  ll ans2;
  for(int bit=1;bit<(1<<n);bit++){
    ll tmp=0;
    for(int i=0;i<n;i++){
      if(bit&(1<<i)) tmp+=A[i];
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(((bit&(1<<i))>0) && ((bit&(1<<j))>0)){
          tmp+=B[i][j];
        }
      }
    }
    if(ans<tmp){
      ans=tmp;
      ans2=bit;
    }
  }
  cout<<ans<<endl;
  bool b=false;
  rep(i,n){
    if(b) cout<<" ";
    if(ans2&(1<<i)){
      cout<<i+1;
      b=true;
    }
  }
  cout<<endl;


  return 0;
}
0