結果

問題 No.519 アイドルユニット
ユーザー Min_25Min_25
提出日時 2017-05-29 22:07:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 1,544 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 106,300 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 06:38:47
合計ジャッジ時間 2,426 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
6,812 KB
testcase_01 AC 24 ms
6,944 KB
testcase_02 AC 9 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 4 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 5 ms
6,944 KB
testcase_25 AC 5 ms
6,940 KB
testcase_26 AC 4 ms
6,944 KB
testcase_27 AC 5 ms
6,940 KB
testcase_28 AC 5 ms
6,944 KB
testcase_29 AC 24 ms
6,940 KB
testcase_30 AC 24 ms
6,944 KB
testcase_31 AC 25 ms
6,940 KB
testcase_32 AC 24 ms
6,940 KB
testcase_33 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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>

#include <unordered_map>

#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;

void solve() {
  const int N_MAX = 24;
  int N;
  while (~scanf("%d", &N)) {
    int cost[N_MAX][N_MAX];
    rep(i, N) rep(j, N) scanf("%d", &cost[i][j]);
    unordered_map<int, int> umap[2];
    auto& curr = umap[0], &next = umap[1];
    curr.reserve(1 << 15), next.reserve(1 << 15);
    curr[(u64(1) << N) - 1] = 0;
    rep(i, N / 2) {
      next.clear();
      for (auto it : curr) {
        int state, sum; tie(state, sum) = it;
        int i = __builtin_ctz(state); 
        for (int s = state & (state - 1), t = s; t; t &= t - 1) {
          int j = __builtin_ctz(t);
          auto& v = next[s ^ (1 << j)];
          v = max(v, sum + cost[i][j]);
        }
      }
      swap(curr, next);
    }
    printf("%d\n", curr[0]);
  }
}

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