結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-01-22 21:37:31
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,913 bytes
コンパイル時間 9,505 ms
コンパイル使用メモリ 135,604 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 17:56:47
合計ジャッジ時間 16,993 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 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,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 13 ms
4,376 KB
testcase_24 AC 26 ms
4,380 KB
testcase_25 AC 108 ms
4,376 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 108 ms
4,380 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 13 ms
4,376 KB
testcase_31 AC 14 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 105 ms
4,376 KB
testcase_34 AC 108 ms
4,380 KB
testcase_35 AC 106 ms
4,376 KB
testcase_36 AC 107 ms
4,384 KB
testcase_37 AC 106 ms
4,380 KB
testcase_38 AC 107 ms
4,380 KB
testcase_39 AC 108 ms
4,380 KB
testcase_40 AC 106 ms
4,380 KB
testcase_41 AC 106 ms
4,380 KB
testcase_42 AC 106 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 107 ms
4,376 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 107 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
//const ll mod = 998244353;
const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }

int main() {
  /* mod は 1e9+7 */
  ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
  cout<< fixed << setprecision(10);
  ll a;
  cin>>a;
  vector<ll> n(a);
  vcin(n);
  vector<vector<ll>> m(a,vector<ll>(a));
  for(int i=0;i<a;i++){
    for(int j=0;j<a;j++){
      cin>>m[i][j];
    }
  }
  ll ans=-inf;
  vector<ll> ans1;
  for(int i=1;i<(1<<a);i++){
    ll tmp=0;
    ll b=i;
    for(int j=0;j<a;j++){
      if(b%2==1){
        tmp+=n[j];
      }
      b/=2;
    }
    bitset<20> s(i);
    for(int x=0;x<a;x++){
      for(int y=x+1;y<a;y++){
        if(s.test(x)&&s.test(y)){
          tmp+=m[x][y];
        }
      }
    }
    if(ans<tmp){
      ans=tmp;
      ll e=i;
      vector<ll> ans2;
      ans1=ans2;
      for(int x=0;x<a;x++){
        if(e%2==1){
          ans1.push_back(x+1);
        }
        e/=2;
      }
    }
  }
  cout<<ans<<endl;
  for(int i=0;i<int(ans1.size());i++){
    cout<<ans1[i];
    if(i!=int(ans1.size())-1){
      cout<<" ";
    }
  }
  cout<<endl;
}
0