Submission #736168

#TimeUsernameProblemLanguageResultExecution timeMemory
736168marvinthangKronican (COCI16_kronican)C++17
100 / 100
662 ms4424 KiB
/************************************* * author: marvinthang * * created: 05.08.2022 12:53:53 * *************************************/ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define div ___div #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define FULL(i) (MASK(i) - 1) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class T> print_op(vector <T>) { out << '{'; for (size_t i = 0; i + 1 < u.size(); ++i) out << u[i] << ", "; if (!u.empty()) out << u.back(); return out << '}'; } template <class U, class V> scan_op(pair <U, V>) { return in >> u.fi >> u.se; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.fi << ", " << u.se << ')'; } template <class A, class B> inline bool minimize(A &a, B b) { A eps = 1e-9; if (a > b + eps) { a = b; return true; } return false; } template <class A, class B> inline bool maximize(A &a, B b) { A eps = 1e-9; if (a + eps < b) { a = b; return true; } return false; } const double PI = 3.1415926535897932384626433832795; // acos(-1.0); atan(-1.0); const int dir[] = {1, 0, -1, 0, 1, 1, -1, -1, 1}; // {2, 1, -2, -1, -2, 1, 2, -1, 2}; const int MAX = 20; int K, N, C[MAX][MAX]; int F[MASK(MAX)]; int dp(int mask) { if (__builtin_popcount(mask) <= K) return 0; int &cur = F[mask]; if (cur != -1) return cur; cur = 1e9; for (int hihi = mask; hihi; hihi &= hihi - 1) { int i = __builtin_ctz(hihi); for (int hjhj = mask; hjhj; hjhj &= hjhj - 1) { int j = __builtin_ctz(hjhj); if (i == j) continue; minimize(cur, dp(mask ^ MASK(i)) + C[i][j]); } } return cur; } void init(void) { cin >> N >> K; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) cin >> C[i][j]; } void process(void) { memset(F, -1, sizeof(F)); cout << dp(FULL(N)) << '\n'; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); file("coci1617_r3_kronican"); init(); process(); // cerr << "Time elapsed: " << TIME << " s.\n"; return (0^0); }

Compilation message (stderr)

kronican.cpp: In function 'int main()':
kronican.cpp:22:69: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 | #define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                             ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:68:2: note: in expansion of macro 'file'
   68 |  file("coci1617_r3_kronican");
      |  ^~~~
kronican.cpp:22:103: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 | #define          file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                               ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
kronican.cpp:68:2: note: in expansion of macro 'file'
   68 |  file("coci1617_r3_kronican");
      |  ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...