Submission #212277

#TimeUsernameProblemLanguageResultExecution timeMemory
212277jk89Raisins (IOI09_raisins)C++14
100 / 100
637 ms21244 KiB
#include <cstdio> #include <vector> #include <algorithm> #include <map> using namespace std; #define f first #define s second const int MAXN = 51; const int INF = 2e9 + 3; int pref[MAXN][MAXN]; int dp[MAXN][MAXN][MAXN][MAXN]; int rob(int x1, int y1, int x2, int y2) { if (dp[x1][y1][x2][y2]) return dp[x1][y1][x2][y2]; if (x1 == x2 && y1 == y2) return 0; int mn = INF; for (int i = x1; i < x2; i++) mn = min(mn, rob(x1, y1, i, y2) + rob(i + 1, y1, x2, y2)); for (int i = y1; i < y2; i++) mn = min(mn, rob(x1, y1, x2, i) + rob(x1, i + 1, x2, y2)); dp[x1][y1][x2][y2] = mn + pref[x2][y2] - pref[x2][y1 - 1] - pref[x1 - 1][y2] + pref[x1 - 1][y1 - 1]; return dp[x1][y1][x2][y2]; } int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { scanf("%d", &pref[i][j]); pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; } } printf("%d", rob(1, 1, n, m)); return 0; }

Compilation message (stderr)

raisins.cpp: In function 'int main()':
raisins.cpp:33: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:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &pref[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...