結果

問題 No.519 アイドルユニット
ユーザー tsutajtsutaj
提出日時 2017-06-19 11:24:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 210 ms / 1,000 ms
コード長 1,132 bytes
コンパイル時間 1,481 ms
コンパイル使用メモリ 166,240 KB
実行使用メモリ 134,656 KB
最終ジャッジ日時 2024-10-02 13:39:32
合計ジャッジ時間 6,434 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
134,552 KB
testcase_01 AC 210 ms
134,400 KB
testcase_02 AC 128 ms
134,400 KB
testcase_03 AC 99 ms
134,400 KB
testcase_04 AC 95 ms
134,528 KB
testcase_05 AC 96 ms
134,528 KB
testcase_06 AC 96 ms
134,656 KB
testcase_07 AC 98 ms
134,400 KB
testcase_08 AC 98 ms
134,656 KB
testcase_09 AC 96 ms
134,528 KB
testcase_10 AC 97 ms
134,400 KB
testcase_11 AC 98 ms
134,528 KB
testcase_12 AC 97 ms
134,528 KB
testcase_13 AC 98 ms
134,528 KB
testcase_14 AC 99 ms
134,528 KB
testcase_15 AC 98 ms
134,528 KB
testcase_16 AC 100 ms
134,528 KB
testcase_17 AC 100 ms
134,528 KB
testcase_18 AC 98 ms
134,528 KB
testcase_19 AC 99 ms
134,528 KB
testcase_20 AC 99 ms
134,528 KB
testcase_21 AC 99 ms
134,528 KB
testcase_22 AC 99 ms
134,528 KB
testcase_23 AC 98 ms
134,400 KB
testcase_24 AC 105 ms
134,400 KB
testcase_25 AC 106 ms
134,528 KB
testcase_26 AC 106 ms
134,400 KB
testcase_27 AC 108 ms
134,400 KB
testcase_28 AC 109 ms
134,528 KB
testcase_29 AC 186 ms
134,400 KB
testcase_30 AC 202 ms
134,400 KB
testcase_31 AC 197 ms
134,528 KB
testcase_32 AC 196 ms
134,656 KB
testcase_33 AC 94 ms
134,400 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