# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1057823 | manhlinh1501 | Dango Maker (JOI18_dango_maker) | C++17 | 247 ms | 199256 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>
using namespace std;
using pii = pair<int, int>;
using i64 = long long;
const int MAXN = 3e3 + 5;
#define ALL(a) (a).begin(), (a).end()
#define R 0
#define D 1
int N, M;
char a[MAXN][MAXN];
int dp[MAXN][MAXN][2];
bool OK[MAXN][MAXN][2];
vector<pii> g[MAXN * 2];
int maxx[MAXN * 2];
bool check(int u, int v) {
return (1 <= u and u <= N and 1 <= v and v <= M);
}
signed main() {
#define TASK "code"
if (fopen(TASK ".inp", "r")) {
freopen(TASK ".inp", "r", stdin);
freopen(TASK ".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/// RGW
cin >> N >> M;
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= M; j++)
cin >> a[i][j];
}
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= M; j++) {
if(a[i][j] == 'R' and a[i][j + 1] == 'G' and a[i][j + 2] == 'W')
OK[i][j][R] = true;
if(a[i][j] == 'R' and a[i + 1][j] == 'G' and a[i + 2][j] == 'W')
OK[i][j][D] = true;
}
}
for(int i = 1; i <= N; i++) {
for(int j = 1; j <= M; j++)
g[i + j].emplace_back(i, j);
}
for(int i = 1; i <= N + M; i++)
reverse(ALL(g[i]));
for(int z = N + M; z >= 1; z--) {
for(auto [u, v] : g[z]) {
// printf("%d %d %d\n", z, u, v);
dp[u][v][R] = dp[u + 1][v - 1][R];
dp[u][v][D] = dp[u + 1][v - 1][D];
if(OK[u][v][R])
dp[u][v][R] = max(dp[u][v][R], max(dp[u + 1][v - 1][R], dp[u + 1][v - 1][D]) + 1);
if(OK[u][v][D]) {
dp[u][v][D] = max(dp[u][v][D], dp[u + 1][v - 1][D] + 1);
if(v - 2 >= 1)
dp[u][v][D] = max(dp[u][v][D], dp[u + 2][v - 2][D] + 1);
if(v - 3 >= 1)
dp[u][v][D] = max(dp[u][v][D], max(dp[u + 3][v - 3][D], dp[u + 3][v - 3][R]) + 1);
}
maxx[z] = max(maxx[z], max(dp[u][v][D], dp[u][v][R]));
}
}
int ans = 0;
for(int i = 1; i <= N + M; i++) {
// cerr << maxx[i] << " ";
ans += maxx[i];
}
cout << ans;
return (0 ^ 0);
}
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... |