func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, e, t, d;   };   vector<node> v[555][555][2];   long long sub[555][2], sum[555][555];   long long dp[2][555][555][2];   int n, m;   const long long inf = 1e18;   void init(int type) {     for (int i = 0; i < m; i++)       for (int j = 0; j < max(n, m) + 1; j++)         for (int k = 0; k < 2; k++) dp[type][i][j][k] = inf;   }   int main() {     int k, x, y, d, t, e;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i < k + 1; i++) {       scanf( %d%d%d%d%d , &x, &y, &d, &t, &e);       if ((x + y) >= t && (x + y - t) % 4 == 0) sum[x][y] += e;       if ((x + y) >= t + 1 && (x + y - t) % 4 == 1) sum[x + d][y - d] += e;       if ((x + y + d) >= t + 2 && (x + y + d - t) % 4 == 2)         v[x + d][y][0].push_back({x, y, e, t, d}), sum[x + d][y] += e;       if ((x + y + d) >= t + 3 && (x + y + d - t) % 4 == 3)         v[x][y + d][1].push_back({x, y, e, t, d}), sum[x][y + d] += e;     }     bool type = 1;     init(0);     dp[0][0][0][0] = 0;     for (int i = 0; i < n; i++) {       init(type);       for (int j = 0; j < m; j++) {         long long nowadd[2] = {sum[i][j], sum[i][j]};         memset(sub, 0, sizeof(sub));         for (auto &xx : v[i][j][0]) {           int x = xx.x, y = xx.y, t = xx.t;           if ((x + y) >= t && (x + y - t) % 4 == 0) sub[xx.d][1] += xx.e;           if ((x + y) >= t + 1 && (x + y - t) % 4 == 1) sub[xx.d][0] += xx.e;         }         for (auto &xx : v[i][j][1]) {           int x = xx.x, y = xx.y, t = xx.t;           if ((x + y) >= t && (x + y - t) % 4 == 0) sub[xx.d][0] += xx.e;         }         for (int kx = 0; kx < max(n, m) + 1; kx++)           for (int k = 0; k < 2; k++) {             if (k && i - kx < 0) continue;             if (!k && j - kx < 0) continue;             nowadd[k] -= sub[kx][k];             if (dp[!type][j][kx][k] != inf) {               if (!k)                 dp[!type][j + 1][kx + 1][0] = min(                     dp[!type][j + 1][kx + 1][0], dp[!type][j][kx][k] + nowadd[0]),                                       dp[type][j][1][1] =                                           min(dp[type][j][1][1],                                               dp[!type][j][kx][k] + nowadd[0]);               else                 dp[!type][j + 1][1][0] =                     min(dp[!type][j + 1][1][0], dp[!type][j][kx][k] + nowadd[1]),                               dp[type][j][kx + 1][1] =                                   min(dp[type][j][kx + 1][1],                                       dp[!type][j][kx][k] + nowadd[1]);             }           }       }       type = !type;     }     long long res = inf;     for (int i = 0; i < max(n, m) + 1; i++)       for (int j = 0; j < 2; j++) res = min(res, dp[!type][m - 1][i][j]);     printf( %I64d n , res);   }   