Submission #375687

#TimeUsernameProblemLanguageResultExecution timeMemory
375687valerikkDango Maker (JOI18_dango_maker)C++17
100 / 100
1886 ms18540 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; // R // RG // RGW // GW // W const int INF = 1e9; int solve(vector<int> d, vector<int> r) { int n = d.size(); vector<vector<int>> dp(3, vector<int>(3, -INF)); dp[0][0] = 0; for (int i = 0; i < n; ++i) { vector<vector<int>> ndp(3, vector<int>(3, -INF)); for (int x = 0; x < 3; ++x) { for (int y = 0; y < 3; ++y) { if (dp[x][y] == -INF) continue; for (int z = 0; z < 3; ++z) { if (z == 1 && (x == 2 || y == 2 || !d[i])) continue; if (z == 2 && !r[i]) continue; ndp[y][z] = max(ndp[y][z], dp[x][y] + !!z); } } } dp = ndp; } int ans = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) ans = max(ans, dp[i][j]); } return ans; } int main() { #ifdef LOCAL freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<vector<char>> grid(n, vector<char>(m)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { cin >> grid[i][j]; } } auto can_down = [&](int x, int y) { if (x + 2 < n && grid[x][y] == 'R' && grid[x + 1][y] == 'G' && grid[x + 2][y] == 'W') return 1; return 0; }; auto can_right = [&](int x, int y) { if (y + 2 < m && grid[x][y] == 'R' && grid[x][y + 1] == 'G' && grid[x][y + 2] == 'W') return 1; return 0; }; int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (i == n - 1 || j == 0) { vector<int> d, r; int curi = i, curj = j; while (curi >= 0 && curj < m) { d.push_back(can_down(curi, curj)); r.push_back(can_right(curi, curj)); --curi; ++curj; } ans += solve(d, r); } } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...