Submission #143686

#TimeUsernameProblemLanguageResultExecution timeMemory
143686tutisCoins (LMIO19_monetos)C++17
20 / 100
83 ms59256 KiB
/*input 0 4 1 5 0 0 1 0 0 0 0 1 0 1 1 1 1 1 0 1 */ #pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int a[302][302]; int t, n, k1, k2; int res[302][302]; int dp[52][52][52 * 52]; void exact() { for (int i = 0; i < 52; i++) { for (int j = 0; j < 52; j++) { for (int t = 0; t < 52 * 52; t++) dp[i][j][t] = -1000000; } } dp[n + 1][n][0] = 0; for (int i = n; i >= 1; i--) { for (int j = 0; j <= n; j++) { for (int j1 = j; j1 <= n; j1++) { for (int k = 0; k + j <= k1; k++) { dp[i][j][k + j] = max(dp[i][j][k + j], dp[i + 1][j1][k] + a[i][j]); } } } } int i = 1; pair<int, int>mx = { -2, -2}; for (int j = 0; j <= n; j++) mx = max(mx, {dp[i][j][k1], j}); int j = mx.second; int k = k1; while (i <= n) { for (int t = 0; t < j; t++) { res[i][n - t] = 1; } int j1 = -1; for (int jj = j; jj <= n; jj++) { if (dp[i][j][k] == dp[i + 1][jj][k - j] + a[i][j]) j1 = jj; } assert(j1 != -1); k -= j; j = j1; i++; } } int main() { ios_base::sync_with_stdio(false); cin >> t >> n >> k1 >> k2; k1 = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < n; j++) cin >> a[i][n - j]; for (int j = 0; j < n; j++) a[i][j + 1] += a[i][j]; k1 += a[i][n]; } exact(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cout << res[i][j] << " "; } cout << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...