Submission #824221

#TimeUsernameProblemLanguageResultExecution timeMemory
824221taherDango Maker (JOI18_dango_maker)C++17
100 / 100
670 ms160380 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "C:\GCC\debug.h" #else #define debug(...) void(42) #endif const int N = 3005; int dp[N][N][2][2]; bool vis[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<char>> g(n, vector<char> (m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> g[i][j]; } } memset(dp, -1, sizeof(dp)); function<int(int, int, int, int)> DP = [&](int i, int j, int previous_row, int third_row) { if (i < 0 || j >= m) { return 0; } vis[i][j] = true; if (dp[i][j][previous_row][third_row] != -1) { return dp[i][j][previous_row][third_row]; } int ans = 0; if (i + 2 < n && g[i][j] == 'R' && g[i + 1][j] == 'G' && g[i + 2][j] == 'W' && !previous_row && !third_row) { ans = max(ans, DP(i - 1, j + 1, 0, previous_row) + 1); } if (j + 2 < m && g[i][j] == 'R' && g[i][j + 1] == 'G' && g[i][j + 2] == 'W') { ans = max(ans, DP(i - 1, j + 1, 1, previous_row) + 1); } ans = max(ans, DP(i - 1, j + 1, 0, previous_row)); return dp[i][j][previous_row][third_row] = ans; }; int res = 0; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < m; j++) { if (!vis[i][j]) { res += DP(i, j, 0, 0); } } } cout << res << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...