結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー firiexpfiriexp
提出日時 2021-01-22 21:27:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,742 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 108,244 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2023-08-27 17:24:55
合計ジャッジ時間 8,210 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 13 ms
4,380 KB
testcase_24 AC 27 ms
4,380 KB
testcase_25 AC 121 ms
5,472 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 121 ms
5,248 KB
testcase_29 AC 7 ms
4,380 KB
testcase_30 AC 14 ms
4,380 KB
testcase_31 AC 13 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 121 ms
5,196 KB
testcase_34 AC 121 ms
5,328 KB
testcase_35 AC 121 ms
5,332 KB
testcase_36 AC 121 ms
5,144 KB
testcase_37 AC 121 ms
5,272 KB
testcase_38 AC 121 ms
5,216 KB
testcase_39 AC 121 ms
5,272 KB
testcase_40 AC 122 ms
5,152 KB
testcase_41 AC 121 ms
5,332 KB
testcase_42 AC 121 ms
5,248 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 121 ms
5,248 KB
testcase_45 AC 1 ms
4,376 KB
testcase_46 AC 121 ms
5,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<vector<int>> b(n, vector<int>(n, 0));
    for (auto &&i : a) scanf("%d", &i);
    for (auto &&i : b) for(auto &&j : i) scanf("%d", &j);
    vector<ll> dp(1 << n, -INF<ll>);
    dp[0] = 0;
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            if(!(i & (1 << j))){
                ll val = dp[i] + a[j];
                for (int k = 0; k < n; ++k) {
                    if((i & (1 << k))) val += b[j][k];
                }
                chmax(dp[i^(1 << j)], val);
            }
        }
    }
    dp[0] = -1;
    int x = max_element(dp.begin(),dp.end()) - dp.begin();
    cout << dp[x] << "\n";
    vector<int> ans;
    for (int i = 0; i < n; ++i) {
        if(x & (1 << i)) ans.emplace_back(i+1);
    }
    for (int i = 0; i < ans.size(); ++i) {
        if(i) printf(" ");
        printf("%d",ans[i]);
    }
    puts("");
    return 0;
}
0