#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll INF=1e9,LINF=1e18,MOD=1e9+7; const ll MAXN=1e3+1,MAXA=1e5+1;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define pb push_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(auto i_:x) cerr<<i_<<" "; cerr<<endl; }
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
void Solve(){
int N,M; cin>>N>>M;
vector<vector<char>> a(N+3,vector<char>(M+3));
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
cin>>a[i][j];
}
}
vector<vector<array<bool,3>>> start(N+M+1,vector<array<bool,3>>(M+1));
for(int i=1;i<=N;i++){
for(int j=1;j<=M;j++){
if(a[i][j]=='R' && a[i+1][j]=='G' && a[i+2][j]=='W') start[i+j][i][1]=true;
if(a[i][j]=='R' && a[i][j+1]=='G' && a[i][j+2]=='W') start[i+j][i][2]=true;
}
}
function<void(int&,int)> smax=[&](int& a,int x){
a=max(a,x);
};
//0 nista
//1 verti
//2 horiz
int res=0;
for(int z=2;z<=N+M;z++){
vector<vector<vector<int>>> dp(N+M+1,vector<vector<int>>(3,vector<int>(3,-INF)));
dp[0][0][0]=0;
for(int i=1;i<=N;i++){
for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
smax(dp[i][0][x],dp[i-1][x][y]);
if(start[z][i][1] && x!=2 && y!=2){
smax(dp[i][1][x],dp[i-1][x][y]+1);
}
if(start[z][i][2]){
smax(dp[i][2][x],dp[i-1][x][y]+1);
}
}
}
}
int tmp=0;
for(int i=0;i<=2;i++){
for(int j=0;j<=2;j++){
tmp=max(tmp,dp[N][i][j]);
}
}
res+=tmp;
}
cout<<res<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t; t=1;
//cin>>t;
while(t--){
Solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
316 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |