# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
914757 | May27_th | Dango Maker (JOI18_dango_maker) | C++17 | 1 ms | 2512 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 int64_t long long
#define double long double
using namespace std;
using type = int64_t;
const long long mod = 1000000007, inf = 1e18;
const int base = 33;
const int N = 2e5 + 10;
const int LG = 20;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
void Minimize(int64_t &a, int64_t b) {if(b < a) a = b;}
void Maximize(int &a, int b) {if(b > a) a = b;}
void Add(int64_t& a, int64_t b) {a = a + b; a %= mod;}
void Dec(int64_t& a, int64_t b) {a = a - b + mod; a %= mod;}
int n, m; char d[3005][3005]; int f[3005][3004];
bool h(int i, int j)
{
return (d[i][j] == 'W') && (d[i][j - 1] == 'G') && (d[i][j - 2] == 'R');
}
bool v(int i, int j)
{
return (d[i][j] == 'W') && (d[i - 1][j] == 'G') && (d[i - 2][j] == 'R');
}
void Solve(void)
{
/**
tim so cach xien que sao cho thu tu la R, G, W
**/
cin >> n >> m;
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
cin >> d[i][j];
}
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= m; j ++){
for(int z = 2; z <= 3; z ++){
Maximize(f[i][j], f[i][max(j - z, 0)] + f[i - 1][j] - f[i - 1][max(j - z, 0)]);
Maximize(f[i][j], f[i][j - 1] + f[max(i - z, 0)][j] - f[max(i - z, 0)][j - 1]);
}
if(j >= 3){
if(h(i, j)){
Maximize(f[i][j], 1 + f[i][j - 3] + f[i - 1][j] - f[i - 1][j - 3]);
}
}
if(i >= 3){
if(v(i, j)){
Maximize(f[i][j], 1 + f[i][j - 1] + f[i - 3][j] - f[i - 3][j - 1]);
}
}
//cout << f[i][j] << " ";
}
//cout << "\n";
}
cout << f[n][m];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
if(fopen("poetry.in", "r")){
freopen("poetry.in", "r", stdin);
freopen("poetry.out", "w", stdout);
}
if(fopen("A.inp", "r")){
freopen("A.inp", "r", stdin);
freopen("A.out", "w", stdout);
}
int tc = 1;
//cin >> tc;
while(tc --){
Solve();
}
}
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... |