Submission #441196

#TimeUsernameProblemLanguageResultExecution timeMemory
441196Aryan_RainaDango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms320 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t #define ld long double #define ar array mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9+7; const int INF = 1e15+5; void amax(int &a, int b) { a = max(a, b); } void solve() { int N, M; cin >> N >> M; string s[N]; for (string &i : s) cin >> i; auto right = [&](int i, int j) { if (j + 2 >= M) return false; return s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W'; }; auto down = [&](int i, int j) { if (i + 2 >= N) return false; return s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W'; }; int ans = 0; for (int x = 0; x < N; x++) { vector<ar<int,3>> dp(M, {0,0,0}); if (down(x, 0)) dp[0][1] = 1; if (right(x, 0)) dp[0][2] = 1; int mx = max({dp[0][0], dp[0][1], dp[0][2]}); for (int i = x-1, j = 1; j < M && i >= 0; i--, j++) { amax(dp[j][0], max(dp[j-1][0], dp[j-1][1])); if (j - 3 >= 0) amax(dp[j][0], dp[j-3][2]); if (down(i, j)) { amax(dp[j][1], max(dp[j-1][0], dp[j-1][1]) + 1); if (j - 3 >= 0) amax(dp[j][1], dp[j-3][2] + 1); } if (right(i, j)) { amax(dp[j][2], max(dp[j-1][0], dp[j-1][1]) + 1); amax(dp[j][2], dp[j-1][2] + 1); } amax(mx, max({dp[j][0], dp[j][1], dp[j][2]})); } ans += mx; } for (int x = 1; x < M; x++) { vector<ar<int,3>> dp(M, {0,0,0}); if (down(N-1, x)) dp[x][1] = 1; if (right(N-1, x)) dp[x][2] = 1; int mx = max({dp[0][0], dp[0][1], dp[0][2]}); for (int i = N-2, j = x + 1; j < M && i >= 0; i--, j++) { amax(dp[j][0], max(dp[j-1][0], dp[j-1][1])); if (j - 3 >= 0) amax(dp[j][0], dp[j-3][2]); if (down(i, j)) { amax(dp[j][1], max(dp[j-1][0], dp[j-1][1]) + 1); if (j - 3 >= 0) amax(dp[j][1], dp[j-3][2] + 1); } if (right(i, j)) { amax(dp[j][2], max(dp[j-1][0], dp[j-1][1]) + 1); amax(dp[j][2], dp[j-1][2] + 1); } amax(mx, max({dp[j][0], dp[j][1], dp[j][2]})); } ans += mx; } cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...