結果
| 問題 |
No.519 アイドルユニット
|
| コンテスト | |
| ユーザー |
Min_25
|
| 提出日時 | 2017-05-29 22:07:49 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 1,000 ms |
| コード長 | 1,544 bytes |
| コンパイル時間 | 962 ms |
| コンパイル使用メモリ | 107,640 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-03 03:55:19 |
| 合計ジャッジ時間 | 1,990 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#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;
}
Min_25