Submission #1352180

#TimeUsernameProblemLanguageResultExecution timeMemory
1352180edoNetrpeljivost (COI23_netrpeljivost)C++20
100 / 100
272 ms16972 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }

  int lg = __lg(n);
  int b = 0;
  vector<ll> dp(n);
  const ll inf = (1ll << 60);
  for (int i = 0; i + 1 < n; ++i) {
    vector<ll> ndp(n, inf);
    for (int x = 0; x < n; ++x) {
      b = 0;
      for (int bit = lg; ~bit; --bit) {
        if ((i >> bit & 1) != ((i + 1) >> bit & 1)) {
          b = bit;
          break;
        }
      }
      for (int x2 = 0; x2 < (1 << b); ++x2) {
        int y = (x ^ x2);
        ndp[y] = min(ndp[y], dp[x] + a[i ^ x][(i + 1) ^ y]);
      }
    }
    dp.swap(ndp);
  }

  cout << ranges::min(dp) << "\n";
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...