# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199742 | Mercenary | Dango Maker (JOI18_dango_maker) | C++14 | 243 ms | 10336 KiB |
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 pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 3e3 + 5;
int dp[maxn][3];
int n , m;
string s[maxn];
bool Up(int i , int j){
return i > 0 && i + 1 < m && s[i][j] == 'G' && s[i - 1][j] == 'R' && s[i + 1][j] == 'W';
}
bool Rig(int i , int j){
return j > 0 && j + 1 < n && s[i][j] == 'G' && s[i][j - 1] == 'R' && s[i][j + 1] == 'W';
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> m >> n;
for(int i = 0 ; i < m ; ++i)cin >> s[i];
int res = 0;
for(int dia = 0 ; dia <= m + n - 2 ; ++dia){
int tmp = 0;
int L = max(0,dia-n+1);int R = min(m,dia+1);
for(int i = L ; i < R ; ++i){
if(i == L){
dp[i][0] = dp[i][1] = dp[i][2] = 0;
if(Up(i,dia-i))dp[i][1] = 1;
if(Rig(i,dia-i))dp[i][2] = 1;
tmp = max(dp[i][1],dp[i][2]);
}else{
dp[i][0] = max({dp[i - 1][0] , dp[i - 1][1] , dp[i - 1][2]});
if(Up(i,dia-i))dp[i][1] = max(dp[i - 1][0] , dp[i - 1][1]) + 1;
else dp[i][1] = 0;
if(Rig(i,dia-i))dp[i][2] = max(dp[i - 1][0] , dp[i - 1][2]) + 1;
else dp[i][2] = 0;
tmp = max({tmp , dp[i][0] , dp[i][1] , dp[i][2]});
}
// cout << dia << " " << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
}
res += tmp;
}
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |