結果

問題 No.519 アイドルユニット
ユーザー Min_25Min_25
提出日時 2017-05-29 02:26:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,336 bytes
コンパイル時間 716 ms
コンパイル使用メモリ 90,744 KB
実行使用メモリ 40,136 KB
最終ジャッジ日時 2024-04-10 05:58:12
合計ジャッジ時間 5,262 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstring>

#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <utility>
#include <set>
#include <map>
#include <queue>

#define _rep(_1, _2, _3, _4, name, ...) name
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c))
#define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__)

using namespace std;
using i16 = short;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using f80 = long double;

const int N_MAX = 24;
i16 memo[1 << N_MAX];
int cost[N_MAX][N_MAX];

int rec(int state) {
  if (!state) return 0;
  if (memo[state] == 0) {
    int i = __builtin_ctz(state);
    int s = state & (state - 1), t = s;
    int best = 0;
    for (; t; t &= t - 1) {
      int j = __builtin_ctz(t);
      best = max(best, cost[i][j] + rec(s ^ (1 << j)));
    }
    memo[state] = best;
  }
  return memo[state];
}

void solve() {
  int N;
  while (~scanf("%d", &N)) {
    rep(i, N) rep(j, N) scanf("%d", &cost[i][j]);
    printf("%d\n", rec((1 << N) - 1));
  }
}

int main() {
  clock_t beg = clock();
  solve();
  clock_t end = clock();
  fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC);
  return 0;
}
0