Submission #410759

#TimeUsernameProblemLanguageResultExecution timeMemory
410759ngpin04Dango Maker (JOI18_dango_maker)C++14
100 / 100
612 ms44800 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; const int N = 3e3 + 5; char a[N][N]; int dp[N][3]; int n,m; bool skew[N][N][3]; bool vis[N][N]; int solve(int i, int j, int pre) { int &res = dp[i][pre]; if (res != -1) return res; if (i > n) return res = 0; if (j > m) return res = solve(i + 1, j - 1, 0); res = 0; for (int val = 0; val <= 2; val++) if ((pre ^ val) != 3 && skew[i][j][val]) res = max(res, solve(i + 1, j - 1, val) + (val > 0)); return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (a[i][j] == 'G') { if (a[i - 1][j] == 'R' && a[i + 1][j] == 'W') skew[i][j][1] = true; if (a[i][j - 1] == 'R' && a[i][j + 1] == 'W') skew[i][j][2] = true; } skew[i][j][0] = true; } int ans = 0; for (int s = 2; s <= n + m; s++) { memset(dp, -1, sizeof(dp)); ans += solve(1, s - 1, 0); } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...