結果
| 問題 | 
                            No.1360 [Zelkova 4th Tune] 協和音
                             | 
                    
| コンテスト | |
| ユーザー | 
                             umezo
                         | 
                    
| 提出日時 | 2021-01-22 22:36:17 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 114 ms / 2,000 ms | 
| コード長 | 844 bytes | 
| コンパイル時間 | 2,712 ms | 
| コンパイル使用メモリ | 197,344 KB | 
| 最終ジャッジ日時 | 2025-01-18 04:51:23 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 47 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:12: warning: ‘ans2’ may be used uninitialized [-Wmaybe-uninitialized]
   45 |     if(ans2&(1<<i)){
      |        ~~~~^~~~~~~
main.cpp:23:6: note: ‘ans2’ was declared here
   23 |   ll ans2;
      |      ^~~~
            
            ソースコード
#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;
}
            
            
            
        
            
umezo