이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ff first
#define ss second
#define N 3005
#define MOD 1000000007
char c[N][N];
bool in[N][2];
int dp[N][4];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin>>n>>m;
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
cin>>c[i][j];
}
}
int res = 0;
for(int s = 2; s <= n + m; ++s){
int l = max(1, s - m);
int r = min(n, s - 1);
for(int i = l; i <= r; ++i){
if(c[i][s - i] == 'R' && c[i][s - i + 1] == 'G' && c[i][s - i + 2] == 'W'){
in[i][0] = 1;
}
if(c[i][s - i] == 'R' && c[i + 1][s - i] == 'G' && c[i + 2][s - i] == 'W'){
in[i][1] = 1;
}
}
memset(dp[l - 1], 0, sizeof dp[l - 1]);
for(int i = l; i <= r; ++i){
memset(dp[i], 0, sizeof dp[i]);
for(int j = 0; j < 4; ++j)
dp[i][j / 2] = max(dp[i][j / 2], dp[i - 1][j]);
if(in[i][1]){
for(int j = 0; j < 4; ++j)
dp[i][j / 2 + 2] = max(dp[i][j / 2 + 2], dp[i - 1][j] + 1);
}
if(in[i][0])
dp[i][0] = max(dp[i - 1][0] + 1, dp[i][0]);
}
res += max(max(dp[r][0], dp[r][1]), max(dp[r][2], dp[r][3]));
for(int i = l; i <= r; ++i){
in[i][0] = in[i][1] = 0;
}
}
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |