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 <bits/stdc++.h>
#define NMAX 2005
#define pb push_back
#define eb emplace_back
#define MOD 100003
#define nl '\n'
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int>
//#pragma GCC optimize("O3")
#define INF 2147483647
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
/*
*
*
================DEMONSTRATION===================
5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
=====================END========================
*/
int n,m;
int mat[3005][3005];
vector<pii>indR;
int rgw[]={0,1,2,3};
int hor(int i,int j)
{
return (mat[i][j-1]==1 && mat[i][j]==2 && mat[i][j+1]==3);
}
int ver(int i,int j)
{
return (mat[i-1][j]==1 && mat[i][j]==2 && mat[i+1][j]==3);
}
int dp[3][3005][3005];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
char x;
cin>>x;
if(x=='R')
{
indR.pb({i,j});
mat[i][j]=1;
}
else if(x=='G')
{
mat[i][j]=2;
}
else
mat[i][j]=3;
}
}
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
dp[0][i][j]=max({dp[0][i-1][j+1],dp[1][i-1][j+1],dp[2][i-1][j+1]});
dp[1][i][j]=max(dp[0][i-1][j+1],dp[1][i-1][j+1])+hor(i,j);
dp[2][i][j]=max(dp[0][i-1][j+1],dp[2][i-1][j+1])+ver(i,j);
}
}
int ans=0;
for(int i=1;i<=n;++i)
{
ans+=max({dp[0][i][1],dp[1][i][1],dp[2][i][1]});
}
for(int i=2;i<=m;++i)
{
ans+=max({dp[0][n][i],dp[1][n][i],dp[2][n][i]});
}
cout<<ans;
return 0;
}
Compilation message (stderr)
dango_maker.cpp:7: warning: "LLONG_MAX" redefined
7 | #define LLONG_MAX 9223372036854775807
|
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
from /usr/include/c++/10/climits:42,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
from dango_maker.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
135 | # define LLONG_MAX __LONG_LONG_MAX__
|
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |