Submission #468358

#TimeUsernameProblemLanguageResultExecution timeMemory
468358JovanBDango Maker (JOI18_dango_maker)C++17
13 / 100
1 ms588 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int N = 3000; string s[N+5]; int dp[N+5][3]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; for(int i=1; i<=n; i++){ string str; cin >> str; s[i] = "." + str; } int res = 0; dp[0][1] = dp[0][2] = -N; for(int si=1; si<=n; si++){ int i = si, j = 1; while(i > 0){ dp[j][0] = max(dp[j-1][0], max(dp[j-1][1], dp[j-1][2])); if(s[i-1][j] == 'R' && s[i][j] == 'G' && s[i+1][j] == 'W') dp[j][1] = 1 + max(dp[j-1][0], dp[j-1][1]); else dp[j][1] = -N; if(s[i][j-1] == 'R' && s[i][j] == 'G' && s[i][j+1] == 'W') dp[j][2] = 1 + max(dp[j-1][0], dp[j-1][2]); else dp[j][2] = -N; i--; j++; } res += max(dp[j-1][0], max(dp[j-1][1], dp[j-1][2])); } for(int sj=2; sj<=m; sj++){ int i = n, j = sj; dp[sj-1][0] = 0; dp[sj-1][1] = dp[sj-1][2] = -N; while(j <= m){ dp[j][0] = max(dp[j-1][0], max(dp[j-1][1], dp[j-1][2])); if(s[i-1][j] == 'R' && s[i][j] == 'G' && s[i+1][j] == 'W') dp[j][1] = 1 + max(dp[j-1][0], dp[j-1][1]); else dp[j][1] = -N; if(s[i][j-1] == 'R' && s[i][j] == 'G' && s[i][j+1] == 'W') dp[j][2] = 1 + max(dp[j-1][0], dp[j-1][2]); else dp[j][2] = -N; i--; j++; } res += max(dp[j-1][0], max(dp[j-1][1], dp[j-1][2])); } cout << res << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...