# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486778 | socho | Dango Maker (JOI18_dango_maker) | C++14 | 422 ms | 79812 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.
/*
Going for full
*/
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
long long a = rand();
long long b = rand();
return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
freopen("problem.in", "r", stdin);
freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
#define endl '\n'
// #define double long double
// #define int long long
// const int MOD = 1000 * 1000 * 1000 + 7;
// const int MOD = 998244353;
// #define cerr if(0) cerr
#define debug(x) cerr << #x << ": " << x << endl;
const int MXN = 3005;
int n, m;
int grid[MXN][MXN];
int can[MXN][MXN];
int dp[MXN][3];
signed main() {
cin >> n >> m;
for (int i=1; i<=n; i++) {
string s;
cin >> s;
for (int j=1; j<=m; j++) {
if (s[j-1] == 'R') grid[i][j] = 1;
if (s[j-1] == 'G') grid[i][j] = 2;
if (s[j-1] == 'W') grid[i][j] = 3;
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (grid[i][j] == 2) {
if (grid[i-1][j] == 1 && grid[i+1][j] == 3) {
can[i][j] += 1;
}
if (grid[i][j-1] == 1 && grid[i][j+1] == 3) {
can[i][j] += 2;
}
}
}
}
int ans = 0;
for (int diag=2; diag<=n+m; diag++) {
dp[0][0] = dp[0][1] = dp[0][2] = 0;
int here = 0;
vector<int> vc;
vc.push_back(-1);
for (int i=1; i<=n; i++) {
int j = diag - i;
if (j >= 1 && j <= m) {
vc.push_back(can[i][j]);
}
}
for (int i=1; i<vc.size(); i++) {
dp[i][0] = dp[i][1] = dp[i][2] = 0;
dp[i][0] = max(max(dp[i-1][0], dp[i-1][1]), dp[i-1][2]);
if (vc[i] & 1) {
dp[i][1] = max(dp[i][1], 1 + max(dp[i-1][0], dp[i-1][1]));
}
if (vc[i] & 2) {
dp[i][2] = max(dp[i][2], 1 + max(dp[i-1][0], dp[i-1][2]));
}
here = max(here, max(max(dp[i][0], dp[i][1]), dp[i][2]));
}
ans += here;
}
cout << ans << endl;
}
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... |