Submission #252340

#TimeUsernameProblemLanguageResultExecution timeMemory
252340SamAndRaisins (IOI09_raisins)C++17
100 / 100
712 ms30484 KiB
#include <bits/stdc++.h> using namespace std; const int N = 55, INF = 1000000009; int n, m; int a[N][N]; int p[N][N]; void pre() { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + a[i][j]; } } } int sum(int x1, int y1, int x2, int y2) { return p[x2][y2] - p[x1 - 1][y2] - p[x2][y1 - 1] + p[x1 - 1][y1 - 1]; } bool c[N][N][N][N]; int dp[N][N][N][N]; int rec(int x1, int y1, int x2, int y2) { if (c[x1][y1][x2][y2]) return dp[x1][y1][x2][y2]; c[x1][y1][x2][y2] = true; if (x1 == x2 && y1 == y2) return 0; dp[x1][y1][x2][y2] = INF; int s = sum(x1, y1, x2, y2); for (int i = x1; i < x2; ++i) dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], s + rec(x1, y1, i, y2) + rec(i + 1, y1, x2, y2)); for (int j = y1; j < y2; ++j) dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], s + rec(x1, y1, x2, j) + rec(x1, j + 1, x2, y2)); return dp[x1][y1][x2][y2]; } int main() { #ifdef SOMETHING freopen("input.txt", "r", stdin); #endif // SOMETHING scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]); } pre(); printf("%d\n", rec(1, 1, n, m)); return 0; }

Compilation message (stderr)

raisins.cpp: In function 'int main()':
raisins.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
raisins.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...