Submission #582614

# Submission time Handle Problem Language Result Execution time Memory
582614 2022-06-24T07:37:48 Z MilosMilutinovic Domino (COCI15_domino) C++14
10 / 160
4000 ms 524288 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());
  int mx = 0, curr = 0;
  vector<int> v;
  vector<bool> was(n * n);
  auto Valid = [&]() {
    bool ok = true;
    for (int i : v) {
      if (was[i]) {
        ok = false;
      }
      was[i] = true;
    }
    for (int i : v) {
      was[i] = false;
    }                
    return ok;
  };
  function<void(int, int)> Gen = [&](int i, int p) {
    if (p + (int) b.size() - i < k || p > k) {
      return;
    }
    if (i == (int) b.size()) {
      if (Valid()) {
        mx = max(mx, curr);
      }
      return;
    }
    Gen(i + 1, p);
    curr -= get<0>(b[i]);
    v.push_back(get<1>(b[i]));
    v.push_back(get<2>(b[i]));
    Gen(i + 1, p + 1);
    curr += get<0>(b[i]);
    v.pop_back();
    v.pop_back();
  };
  Gen(0, 0);
  cout << sum - mx << '\n';                                               
  return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 4091 ms 47212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4070 ms 852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1581 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4026 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 422892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4034 ms 187940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1596 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4093 ms 852 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1587 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 2256 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 212 KB Output is correct
2 Correct 64 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1589 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4029 ms 1316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4074 ms 187964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4090 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1584 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -