Submission #446145

# Submission time Handle Problem Language Result Execution time Memory
446145 2021-07-21T06:05:02 Z JerryLiu06 Raisins (IOI09_raisins) C++17
100 / 100
201 ms 30612 KB
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using db = double;
using str = string;
 
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
 
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
 
#define mp make_pair
#define f first
#define s second
 
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert 
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
 
#define lb lower_bound
#define ub upper_bound
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a)
#define EACH(a, x) for (auto& a : x)
 
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); }
ll fdiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
template<class T> void remDup(vector<T>& v) { sor(v); v.erase(unique(all(v)), v.end()); }
 
const int MOD = 1e9 + 7;
const int MX = 55;
const ll INF = 1e18;

int N, M; int pref[MX][MX]; ll DP[MX][MX][MX][MX];

int query(int X1, int X2, int Y1, int Y2) {
    return pref[X2][Y2] - pref[X1 - 1][Y2] - pref[X2][Y1 - 1] + pref[X1 - 1][Y1 - 1];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> N >> M; FOR(i, 1, N + 1) FOR(j, 1, M + 1) { 
        cin >> pref[i][j]; pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; 
    }
    ROF(X1, 1, N + 1) FOR(X2, X1, N + 1) ROF(Y1, 1, M + 1) FOR(Y2, Y1, M + 1) {
        if (X1 == X2 && Y1 == Y2) continue; DP[X1][X2][Y1][Y2] = query(X1, X2, Y1, Y2); ll MN = INF;

        FOR(X, X1, X2) ckmin(MN, DP[X1][X][Y1][Y2] + DP[X + 1][X2][Y1][Y2]);
        FOR(Y, Y1, Y2) ckmin(MN, DP[X1][X2][Y1][Y] + DP[X1][X2][Y + 1][Y2]);

        DP[X1][X2][Y1][Y2] += MN;
    }
    cout << DP[1][N][1][M];
}

Compilation message

raisins.cpp: In function 'int main()':
raisins.cpp:72:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   72 |         if (X1 == X2 && Y1 == Y2) continue; DP[X1][X2][Y1][Y2] = query(X1, X2, Y1, Y2); ll MN = INF;
      |         ^~
raisins.cpp:72:45: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   72 |         if (X1 == X2 && Y1 == Y2) continue; DP[X1][X2][Y1][Y2] = query(X1, X2, Y1, Y2); ll MN = INF;
      |                                             ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 716 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 3 ms 2636 KB Output is correct
9 Correct 5 ms 4352 KB Output is correct
10 Correct 7 ms 5000 KB Output is correct
11 Correct 6 ms 3772 KB Output is correct
12 Correct 20 ms 9420 KB Output is correct
13 Correct 27 ms 12236 KB Output is correct
14 Correct 7 ms 4556 KB Output is correct
15 Correct 34 ms 13900 KB Output is correct
16 Correct 5 ms 6860 KB Output is correct
17 Correct 18 ms 11840 KB Output is correct
18 Correct 105 ms 24556 KB Output is correct
19 Correct 170 ms 28244 KB Output is correct
20 Correct 201 ms 30612 KB Output is correct