Submission #617990


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAX = 333;
const ll INF = 1ll<<55;
ll B[MAX][MAX];
ll total[MAX][MAX];
ll memoy[MAX][MAX];
ll memox[MAX][MAX];
ll dpy[MAX][MAX];
ll dpx[MAX][MAX];

ll getSum(int y1, int x1, int y2, int x2) {
    return total[y2][x2] - total[y2][x1-1] - total[y1-1][x2] + total[y1-1][x1-1];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        cin >> B[i][j];
    }
    for (int i = 1; i <= H; i++) for (int j = 1; j <= W; j++) {
        total[i][j] = total[i-1][j] + total[i][j-1] - total[i-1][j-1] + B[i-1][j-1];
    }
    // memo
    for (int y1 = 1; y1 <= H; y1++) for (int y2 = y1; y2 <= H; y2++) {
        memoy[y1][y2] = -INF;
        vector<ll> memo(W+1);
        for (int i = 1; i <= W; i++) memo[i] = min(memo[i-1], getSum(y1, 1, y2, i));
        for (int r = 1; r <= W; r++) memoy[y1][y2] = max(memoy[y1][y2], getSum(y1, 1, y2, r) - memo[r-1]);
        //for (int x1 = 1; x1 <= W; x1++) for (int x2 = x1; x2 <= W; x2++) {
        //    memoy[y1][y2] = max(memoy[y1][y2], getSum(y1, x1, y2, x2));
        //}
    }
    for (int x1 = 1; x1 <= W; x1++) for (int x2 = x1; x2 <= W; x2++) {
        memox[x1][x2] = -INF;
        vector<ll> memo(H+1);
        for (int i = 1; i <= H; i++) memo[i] = min(memo[i-1], getSum(1, x1, i, x2));
        for (int r = 1; r <= H; r++) memox[x1][x2] = max(memox[x1][x2], getSum(1, x1, r, x2) - memo[r-1]);
        //for (int y1 = 1; y1 <= H; y1++) for (int y2 = y1; y2 <= H; y2++) {
        //    memox[x1][x2] = max(memox[x1][x2], getSum(y1, x1, y2, x2));
        //}
    }
    // dp
    for (int x1 = 1; x1 <= W; x1++) for (int x3 = x1+1; x3 <= W+1; x3++) {
        dpx[x1][x3] = -INF;
        for (int x2 = x1; x2 < x3; x2++) dpx[x1][x3] = max(dpx[x1][x3], memox[x1][x2]);
    }
    for (int y1 = 1; y1 <= H; y1++) for (int y3 = y1+1; y3 <= H+1; y3++) {
        dpy[y1][y3] = -INF;
        for (int y2 = y1; y2 < y3; y2++) dpy[y1][y3] = max(dpy[y1][y3], memoy[y1][y2]);
    }
    // solve
    ll ans = -INF;
    for (int x1 = 1; x1 <= W; x1++) for (int x3 = x1+1; x3 <= W; x3++) {
        ans = max(ans, dpx[x1][x3] + dpx[x3][W+1]);
    }
    for (int y1 = 1; y1 <= H; y1++) for (int y3 = y1+1; y3 <= H; y3++) {
        ans = max(ans, dpy[y1][y3] + dpy[y3][H+1]);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - 庭園
User mayoko
Language C++11 (GCC 4.9.2)
Score 100
Code Size 3029 Byte
Status AC
Exec Time 288 ms
Memory 5156 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 50 / 50 50 / 50
Status
AC × 4
AC × 15
AC × 30
Set Name Test Cases
Sample sample0.txt, sample1.txt, sample2.txt, sample3.txt
Subtask1 subtask0_0.txt, subtask0_1.txt, subtask0_10.txt, subtask0_11.txt, subtask0_12.txt, subtask0_13.txt, subtask0_14.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt
All subtask0_0.txt, subtask0_1.txt, subtask0_10.txt, subtask0_11.txt, subtask0_12.txt, subtask0_13.txt, subtask0_14.txt, subtask0_2.txt, subtask0_3.txt, subtask0_4.txt, subtask0_5.txt, subtask0_6.txt, subtask0_7.txt, subtask0_8.txt, subtask0_9.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt
Case Name Status Exec Time Memory
sample0.txt AC 26 ms 800 KB
sample1.txt AC 24 ms 800 KB
sample2.txt AC 25 ms 928 KB
sample3.txt AC 28 ms 924 KB
subtask0_0.txt AC 28 ms 1572 KB
subtask0_1.txt AC 29 ms 1560 KB
subtask0_10.txt AC 29 ms 1448 KB
subtask0_11.txt AC 29 ms 1436 KB
subtask0_12.txt AC 29 ms 1500 KB
subtask0_13.txt AC 27 ms 1556 KB
subtask0_14.txt AC 27 ms 1496 KB
subtask0_2.txt AC 28 ms 1368 KB
subtask0_3.txt AC 29 ms 1448 KB
subtask0_4.txt AC 29 ms 1448 KB
subtask0_5.txt AC 29 ms 1444 KB
subtask0_6.txt AC 30 ms 1432 KB
subtask0_7.txt AC 29 ms 1440 KB
subtask0_8.txt AC 28 ms 1448 KB
subtask0_9.txt AC 30 ms 1448 KB
subtask1_0.txt AC 214 ms 4772 KB
subtask1_1.txt AC 242 ms 4896 KB
subtask1_10.txt AC 205 ms 4776 KB
subtask1_11.txt AC 263 ms 5152 KB
subtask1_12.txt AC 229 ms 4896 KB
subtask1_13.txt AC 269 ms 5156 KB
subtask1_14.txt AC 220 ms 5028 KB
subtask1_2.txt AC 261 ms 5148 KB
subtask1_3.txt AC 217 ms 4896 KB
subtask1_4.txt AC 231 ms 4904 KB
subtask1_5.txt AC 287 ms 5156 KB
subtask1_6.txt AC 247 ms 5024 KB
subtask1_7.txt AC 231 ms 4900 KB
subtask1_8.txt AC 288 ms 5156 KB
subtask1_9.txt AC 231 ms 4908 KB