This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 1e9+9;
void solve(){
int n, m;
cin >> n >> m;
vector<string> s(n+1);
for(int i = 1; i <= n; i++){
cin >> s[i];
s[i] = ' ' + s[i];
}
vector<vector<bool>> ud(n+1, vector<bool>(m+1, 0)), lr(n+1, vector<bool>(m+1, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(i > 1 && i < n){
if(s[i-1][j] == 'R' && s[i][j] == 'G' && s[i+1][j] == 'W'){
ud[i][j] = 1;
}
}
if(j > 1 && j < m){
if(s[i][j-1] == 'R' && s[i][j] == 'G' && s[i][j+1] == 'W'){
lr[i][j] = 1;
}
}
}
}
auto chmax = [&](int &a, int b) -> void{
a = max(a, b);
};
int ans = 0;
for(int sum = 2; sum <= 2*n; sum++){
vector<pair<int, int>> items;
for(int i = 1; i <= n; i++){
int j = sum-i;
if(j < 1 || j > m) continue;
items.push_back({ud[i][j], lr[i][j]});
}
vector<int> f(3, -INF), prv(3, -INF);
f[0] = 0;
for(auto it : items){
prv = f;
fill(f.begin(), f.end(), -INF);
chmax(f[0], max({prv[0], prv[1], prv[2]}));
if(it.first) chmax(f[1], max(prv[0], prv[2])+1);
if(it.second) chmax(f[2], max(prv[0], prv[1])+1);
}
int res = 0;
for(int j = 0; j <= 2; j++) chmax(res, f[j]);
ans += res;
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |