結果

問題 No.519 アイドルユニット
ユーザー tsutajtsutaj
提出日時 2017-06-19 11:24:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 1,132 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 163,624 KB
実行使用メモリ 134,832 KB
最終ジャッジ日時 2024-04-10 11:40:20
合計ジャッジ時間 4,570 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
134,672 KB
testcase_01 AC 140 ms
134,744 KB
testcase_02 AC 66 ms
134,732 KB
testcase_03 AC 38 ms
134,536 KB
testcase_04 AC 34 ms
134,640 KB
testcase_05 AC 35 ms
134,652 KB
testcase_06 AC 35 ms
134,692 KB
testcase_07 AC 34 ms
134,616 KB
testcase_08 AC 34 ms
134,644 KB
testcase_09 AC 35 ms
134,516 KB
testcase_10 AC 35 ms
134,704 KB
testcase_11 AC 36 ms
134,692 KB
testcase_12 AC 35 ms
134,684 KB
testcase_13 AC 37 ms
134,832 KB
testcase_14 AC 37 ms
134,652 KB
testcase_15 AC 36 ms
134,648 KB
testcase_16 AC 36 ms
134,608 KB
testcase_17 AC 37 ms
134,540 KB
testcase_18 AC 37 ms
134,500 KB
testcase_19 AC 36 ms
134,636 KB
testcase_20 AC 37 ms
134,712 KB
testcase_21 AC 37 ms
134,620 KB
testcase_22 AC 38 ms
134,612 KB
testcase_23 AC 37 ms
134,588 KB
testcase_24 AC 43 ms
134,688 KB
testcase_25 AC 43 ms
134,764 KB
testcase_26 AC 43 ms
134,656 KB
testcase_27 AC 45 ms
134,504 KB
testcase_28 AC 45 ms
134,672 KB
testcase_29 AC 118 ms
134,612 KB
testcase_30 AC 139 ms
134,484 KB
testcase_31 AC 131 ms
134,584 KB
testcase_32 AC 132 ms
134,804 KB
testcase_33 AC 34 ms
134,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, board[25][25];
int memo[1<<24];

void solve(int S) {
    rep(i,0,N) {
        if(S >> i & 1) continue;
        rep(j,i+1,N) {
            if(S >> j & 1) continue;
            int nbit = S | (1<<i) | (1<<j);
            int ncost = memo[S] + board[i][j];
            if(ncost > memo[nbit]) {
                memo[nbit] = ncost;
                solve(nbit);
            }
        }
        break;
    }
}

signed main() {
    cin >> N;
    rep(i,0,N) rep(j,0,N) cin >> board[i][j];
    memset(memo, -1, sizeof(memo));
    memo[0] = 0;
    solve(0);
    cout << memo[(1<<N)-1] << endl;
    return 0;
}
0