답안 #222006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222006 2020-04-11T18:32:19 Z Haunted_Cpp Kronican (COCI16_kronican) C++17
100 / 100
1059 ms 4480 KB
/*
 author: Haunted_Cpp
 "Persistence guarantees that results are inevitable"
*/
 
#include <iostream>
#include <algorithm>
#include <vector>
 
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
 
const int N = 20 + 1;

int dp [1 << N], g [N][N], n, k;

int dfs (int mask) {
  if (__builtin_popcount(mask) <= k) return 0;
  int &res = dp[mask];
  if (res) return res;
  res = 1e9;
  for (int i = 0; i < n; i++) {
    if (((mask >> i) & 1) == 0) continue;
    for (int j = i + 1; j < n; j++) {
      if (((mask >> j) & 1) == 0) continue;
      res = min (res, g[i][j] + dfs (mask ^ (1 << i)));
      res = min (res, g[j][i] + dfs (mask ^ (1 << j)));
    }
  }
  return res;
}

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> g[i][j];
    }
  }
  cout << dfs ((1 << n) - 1) << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 13 ms 384 KB Output is correct
6 Correct 23 ms 512 KB Output is correct
7 Correct 41 ms 640 KB Output is correct
8 Correct 91 ms 896 KB Output is correct
9 Correct 1059 ms 4480 KB Output is correct
10 Correct 873 ms 3832 KB Output is correct