Submission #254120

# Submission time Handle Problem Language Result Execution time Memory
254120 2020-07-29T11:31:47 Z rama_pang Coins (LMIO19_monetos) C++14
20 / 100
86 ms 143736 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 55;
const int INF = 1e8;

int N, K1, K2;
int A[MAXN][MAXN];
int ans[MAXN][MAXN];

int L[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN * MAXN];
array<int, 3> pr[MAXN][MAXN][MAXN * MAXN];

void Solve() {
  int shift = max(1, N / 50);
  int NN = N / shift;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      int di = (i + shift - 1) / shift;
      int dj = (j + shift - 1) / shift;
      L[di][dj] += A[i][j];
    }
  }
  for (int i = 1; i <= NN; i++) {
    for (int j = 1; j <= NN; j++) {
      L[i][j] += L[i][j - 1];
    }
  }

  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < MAXN; j++) {
      for (int k = 0; k < MAXN * MAXN; k++) {
        dp[i][j][k] = INF;
        pr[i][j][k] = {-1, -1, -1};
      }
    }
  }

  dp[NN + 1][0][0] = 0;
  for (int i = NN + 1; i >= 1; i--) {
    for (int j = 0; j <= NN; j++) {
      for (int k = 0; k <= NN * NN / 2; k++) if (dp[i][j][k] != INF) {
        if (k + j <= NN * NN / 2) {
          if (dp[i - 1][j][k + j] > dp[i][j][k] + L[i - 1][j]) {
            dp[i - 1][j][k + j] = dp[i][j][k] + L[i - 1][j];
            pr[i - 1][j][k + j] = {i, j, k};
          }
        }
        if (k <= NN * NN / 2) {
          if (dp[i][j + 1][k] > dp[i][j][k]) {
            dp[i][j + 1][k] = dp[i][j][k];
            pr[i][j + 1][k] = {i, j, k};
          }
        }
      }
    }
  }
  vector<vector<int>> res(NN + 1, vector<int>(NN + 1));
  int i = 1, j = NN, k = NN * NN / 2;
  while (i != -1) {
    if (pr[i][j][k][0] == i + 1) {
      for (int l = 1; l <= NN; l++) {
        res[i][l] = (l > j);
      }
    }
    tie(i, j, k) = make_tuple(pr[i][j][k][0], pr[i][j][k][1], pr[i][j][k][2]);
  }

  for (int i = 1; i <= NN; i++) {
    for (int j = 1; j <= NN; j++) {
      for (int k = 1; k <= shift; k++) {
        for (int l = 1; l <= shift; l++) {
          ans[(i - 1) * shift + k][(j - 1) * shift + l] = res[i][j];
        }
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int T;
  cin >> T >> N >> K1 >> K2;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      cin >> A[i][j];
    }
  }
  Solve();
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      cout << ans[i][j] << " \n"[j == N];
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 71 ms 143736 KB K = 17
2 Correct 86 ms 143608 KB K = 576
3 Incorrect 76 ms 143612 KB Unexpected end of file - int32 expected
4 Incorrect 80 ms 143608 KB Unexpected end of file - int32 expected
5 Incorrect 81 ms 143608 KB Unexpected end of file - int32 expected
6 Incorrect 83 ms 143608 KB Unexpected end of file - int32 expected
7 Incorrect 72 ms 143608 KB Unexpected end of file - int32 expected
8 Incorrect 73 ms 143736 KB Unexpected end of file - int32 expected
9 Incorrect 73 ms 143552 KB Unexpected end of file - int32 expected
10 Incorrect 78 ms 143608 KB Unexpected end of file - int32 expected