結果
問題 | No.1360 [Zelkova 4th Tune] 協和音 |
ユーザー |
![]() |
提出日時 | 2021-01-22 21:27:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 1,954 ms |
コンパイル使用メモリ | 172,820 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-27 21:21:12 |
合計ジャッジ時間 | 6,823 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int main(){ int N; cin >> N; vector<ll> v(N); rep(i,N) cin >> v[i]; vector<vector<ll>> w(N, vector<ll>(N)); rep(i,N){ rep(j,N){ cin >> w[i][j]; } } ll mx = -1; ll mx_S = 0; for(ll S = 1; S<(1<<N); S++){ ll sum = 0; rep(i,N) if((S>>i)&1){ sum += v[i]; REP(j,i+1,N) if((S>>j)&1){ sum += w[i][j]; } } if(mx < sum){ mx = sum; mx_S = S; } } cout << mx << endl; vector<ll> ret; rep(i,N) if((mx_S>>i)&1){ ret.push_back(i+1); } rep(i,ret.size()){ if(i>0) cout << " "; cout << ret[i]; } cout << endl; return 0; }