Submission #2036279


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧  
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     
    /   \     | |     
    /   / ̄ ̄ ̄ ̄/  |  
  __(__ニつ/     _/ .| .|____  
     \/____/ (u ⊃  
---------------------------------------------------------------------------------------------------*/






int H, W; ll P[10][50101], F[10][50101];
//---------------------------------------------------------------------------------------------------
vector<ll> update(vector<ll> &dp, ll *p, ll *f) {
    vector<ll> A(W), B(W), res(W);

    rep(x, 1, W) A[x] = max(p[x - 1] - f[x - 1], A[x - 1] + p[x - 1] - f[x - 1] * 2);
    rrep(x, W - 2, 0) B[x] = max(p[x + 1] - f[x + 1], B[x + 1] + p[x + 1] - f[x + 1] * 2);

    ll ma = -infl;
    rep(x, 0, W) {
        ma = max(max(ma + p[x] - f[x], dp[x] + A[x] + p[x] - f[x] * 2), dp[x] + p[x] - f[x]);
        res[x] = max(ma + B[x] - f[x], ma);
    }
    return res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) rep(x, 0, W) cin >> P[y][x];
    rep(y, 0, H) rep(x, 0, W) cin >> F[y][x];

    vector<ll> dp(W, -infl);
    dp[0] = 0;

    rep(y, 0, H) {
        auto pd1 = update(dp, P[y], F[y]);

        reverse(dp.begin(), dp.end());
        reverse(P[y], P[y] + W);
        reverse(F[y], F[y] + W);

        auto pd2 = update(dp, P[y], F[y]);

        rep(x, 0, W) dp[x] = max(pd1[x], pd2[W - 1 - x]);
    }

    rep(x, 0, W) printf("%lld\n", dp[x]);
}

Submission Info

Submission Time
Task D - 建物
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2491 Byte
Status AC
Exec Time 94 ms
Memory 10100 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 23
Set Name Test Cases
Sample sample0.txt, sample1.txt, sample2.txt
All 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, hand0.txt, hand1.txt, sample0.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
01-00.txt AC 94 ms 10100 KB
01-01.txt AC 94 ms 10100 KB
01-02.txt AC 94 ms 10100 KB
01-03.txt AC 94 ms 10100 KB
01-04.txt AC 94 ms 10100 KB
01-05.txt AC 89 ms 10100 KB
01-06.txt AC 89 ms 10100 KB
01-07.txt AC 89 ms 10100 KB
01-08.txt AC 89 ms 10100 KB
01-09.txt AC 89 ms 10100 KB
01-10.txt AC 89 ms 10100 KB
01-11.txt AC 89 ms 10100 KB
01-12.txt AC 89 ms 10100 KB
01-13.txt AC 74 ms 10100 KB
01-14.txt AC 78 ms 10100 KB
01-15.txt AC 85 ms 10100 KB
01-16.txt AC 85 ms 10100 KB
01-17.txt AC 84 ms 10100 KB
hand0.txt AC 2 ms 4352 KB
hand1.txt AC 2 ms 4352 KB
sample0.txt AC 2 ms 4352 KB
sample1.txt AC 2 ms 4352 KB
sample2.txt AC 2 ms 4352 KB