이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define mp make_pair
#define eb emplace_back
using namespace std;
typedef pair<int,int> pii;
void debug(){
cout<<"\n";
}
template <class T,class ... U >
void debug(T a, U ... b){
cout<<a<<" ",debug(b...);
}
const int N=3e3+7;
const int INF=1e18;
char c[N][N];
int dp[N][3];
signed main(){
quick
int n,m;
cin>>n>>m;
rep(i,1,n){
rep(j,1,m) cin>>c[i][j];
}
int ans=0;
rep(l,2,n+m){
fill(dp[0],dp[N-1]+3,0);
int ret=0;
rep(i,1,l-1){
rep(x,0,2){
dp[i][0]=max(dp[i][0],dp[i-1][x]);
}
int j=l-i;
if(j<0||j>m) continue;
if(i+1<=n&&i-1>=1&&c[i-1][j]=='R'&&c[i][j]=='G'&&c[i+1][j]=='W'){
dp[i][1]=max(dp[i-1][0],dp[i-1][2])+1;
}
if(j+1<=m&&j-1>=1&&c[i][j-1]=='R'&&c[i][j]=='G'&&c[i][j+1]=='W'){
dp[i][2]=max(dp[i-1][0],dp[i-1][1])+1;
}
ret=max({dp[i][0],dp[i][1],dp[i][2],ret});
}
ans+=ret;
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |