1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| const int maxn = 200 + 10; const int inf = 0x3f3f3f3f; char mp[maxn][maxn];
const int dx[] = {0, -1, 1, 0, 0}; const int dy[] = {0, 0, 0, -1, 1};
int n, m, K; int sx, sy; int S[maxn], T[maxn], D[maxn];
bool valid(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; }
void dbg() { _rep(i, 1, n) printf("%s", mp[i]+1), printf("\n"); }
int f[maxn][maxn][maxn]; int ans;
class A { public: int f, step; A() {} A(int f, int step) : f(f), step(step) {} } que[maxn];
void dp(int i, int x, int y) { int L = T[i] - S[i] + 1; int d = D[i];
int num = 0; int l = 1, r = 0; while (valid(x, y)) { if(mp[x][y] == 'x') { l = 1, r = 0; } else { if(f[i-1][x][y] != -inf) { while (l <= r && que[r].f + num - que[r].step <= f[i-1][x][y]) r--; que[++r] = A(f[i-1][x][y], num); } }
while (l <= r && num - que[l].step > L) l++; if(l <= r) f[i][x][y] = que[l].f + num - que[l].step; else f[i][x][y] = -inf;
chmax(ans, f[i][x][y]);
num++; x += dx[d], y += dy[d]; } }
void init() { memset(f, -inf, sizeof(f)); f[0][sx][sy] = 0; ans = 0; }
void solve() { init(); _rep(i, 1, K) { int d = D[i];
if(d == 1) { _rep(j, 1, m) dp(i, n, j); } else if(d == 2) { _rep(j, 1, m) dp(i, 1, j); } else if(d == 3) { _rep(j, 1, n) dp(i, j, m); } else { _rep(j, 1, n) dp(i, j, 1); } }
printf("%d\n", ans); }
int main() { freopen("input.txt", "r", stdin); scanf("%d%d%d%d%d", &n, &m, &sx, &sy, &K); _rep(i, 1, n) scanf("%s", mp[i]+1); _rep(i, 1, K) scanf("%d%d%d", &S[i], &T[i], &D[i]);
// dbg(); // then solve the problem
solve(); }
|