// #pragma GCC optimize("O3")
// #pragma GCC optimization("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>
const ll mod = 1e9 + 7;
const int MAXN = 3e3 + 5;
const ll oo = 1e18 + 7;
const int base = 10;
int m, n;
char a[MAXN][MAXN];
int chk1(int x, int y){
if(x-1<1 || x+1>m){
return 0;
}
return (a[x-1][y]=='R' && a[x][y]=='G' && a[x+1][y]=='W');
}
int chk2(int x, int y){
if(y-1<1 || y+1>n){
return 0;
}
return (a[x][y-1]=='R' && a[x][y]=='G' && a[x][y+1]=='W');
}
vector<pii> vec;
int f[2*MAXN][3];
int dp(int i, int t){
if(i>(int)vec.size()-1){
return 0;
}
if(f[i][t]!=-1){
return f[i][t];
}
int x=vec[i].fi, y=vec[i].se;
int ans=0;
ans=max(ans, dp(i+1, 0));
if(chk1(x, y) && t!=2){
ans=max(ans, dp(i+1, 1)+1);
}
if(chk2(x, y) && t!=1){
ans=max(ans, dp(i+1, 2)+1);
}
return f[i][t]=ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("test.txt", "r", stdin);
// freopen("o2.out", "w", stdout);
if(fopen(".inp", "r")){
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> m >> n;
FOR(i, 1, m){
FOR(j, 1, n){
cin >> a[i][j];
}
}
int ans=0;
FOR(id, 2, m+n){
int x, y;
if(id<=n+1){
x=1;
y=id-x;
}
else{
y=n;
x=id-y;
}
vec.clear();
while(x<=m && y>=1){
vec.push_back({x, y});
x++;
y--;
}
FOR(i, 0, (int)vec.size()){
FOR(t, 0, 2){
f[i][t]=-1;
}
}
ans+=dp(0, 0);
}
cout << ans;
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:69:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |