Submission #582634

# Submission time Handle Problem Language Result Execution time Memory
582634 2022-06-24T07:49:02 Z MilosMilutinovic Domino (COCI15_domino) C++14
100 / 160
4000 ms 125588 KB
/**
 *    author:  wxhtzdy
 *    created: 24.06.2022 09:28:57
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k;
  cin >> n >> k;
  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 sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      sum += a[i][j];
    }
  }
  vector<tuple<int, int, int>> b;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i + 1 < n) {
        b.emplace_back(-a[i][j] - a[i + 1][j], i * n + j, (i + 1) * n + j);
      }
      if (j + 1 < n) {
        b.emplace_back(-a[i][j] - a[i][j + 1], i * n + j, i * n + j + 1);
      }
    }
  }
  sort(b.begin(), b.end()); 
  b.resize(min((int) b.size(), 41));
  int mx = 0, curr = 0;
  vector<int> cnt(n * n);
  function<void(int, int)> Gen = [&](int i, int p) {
    if (p > k || p + (int) b.size() - i < k) {
      return;
    }
    if (i == (int) b.size()) {
      mx = max(mx, curr);
      return;
    }
    Gen(i + 1, p);
    if (cnt[get<1>(b[i])] == 0 && cnt[get<2>(b[i])] == 0) {
      curr -= get<0>(b[i]);
      cnt[get<1>(b[i])]++;
      cnt[get<2>(b[i])]++;
      Gen(i + 1, p + 1);
      cnt[get<1>(b[i])]--;
      cnt[get<2>(b[i])]--;
      curr += get<0>(b[i]);
    }
  };
  Gen(0, 0);
  cout << sum - mx << '\n';                                               
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 83 ms 8076 KB Output is correct
2 Correct 40 ms 8116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1380 ms 125568 KB Output is correct
2 Correct 737 ms 125512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 889 ms 107768 KB Output is correct
2 Correct 442 ms 107732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 381 ms 31572 KB Output is correct
2 Correct 211 ms 31572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1790 ms 125564 KB Output is correct
2 Correct 850 ms 125588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 696 ms 468 KB Output is correct
2 Correct 127 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2136 ms 125556 KB Output is correct
2 Incorrect 846 ms 125564 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3169 ms 788 KB Output is correct
2 Incorrect 265 ms 788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4083 ms 125564 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4059 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 31576 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 296 KB Output is correct
2 Correct 95 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4061 ms 125572 KB Time limit exceeded
2 Halted 0 ms 0 KB -