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 fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 5010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
int f[2 * N][3], a[N][N], good[N][N];
int n, m;
bool down(int i, int j)
{
return a[i][j] == 0 and a[i + 1][j] == 1 and a[i + 2][j] == 2;
}
bool right(int i, int j)
{
return a[i][j] == 0 and a[i][j + 1] == 1 and a[i][j + 2] == 2;
}
main()
{
#define name "TASK"
if (fopen(name ".inp", "r"))
{
freopen(name ".inp", "r", stdin);
freopen(name ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
fo(i, 1, n) fo(j, 1, m)
{
char t;
cin >> t;
if (t == 'R')
a[i][j] = 0;
if (t == 'G')
a[i][j] = 1;
if (t == 'W')
a[i][j] = 2;
}
fo(i, 1, n) fo(j, 1, m)
{
if (down(i, j))
good[i + 1][j] ^= 1;
if (right(i, j))
good[i][j + 1] ^= 2;
}
int ans = 0;
fo(sum, 2, n + m)
{
int res = 0;
bool st = 0;
fo(i, 1, n)
{
int j = sum - i;
if(j > m or i > sum) continue;
if (!st)
{
st = 1;
f[i][0] = f[i][1] = f[i][2] = 0;
if (good[i][j] & 1)
f[i][1] = 1;
if (good[i][j] & 2)
f[i][2] = 1;
maximize(res, max({f[i][0], f[i][1], f[i][2]}));
continue;
}
else
{
f[i][0] = max({f[i - 1][0], f[i - 1][1], f[i - 1][2]});
f[i][1] = f[i][2] = 0;
if (good[i][j] & 1)
f[i][1] = 1;
if(i > 1) f[i][1] += max(f[i - 1][1],f[i - 1][0]);
if (good[i][j] & 2)
f[i][2] = 1;
if(i > 1) f[i][2] += max(f[i - 1][2],f[i - 1][0]);
}
maximize(res, max({f[i][0], f[i][1], f[i][2]}));
}
ans += res;
}
cout << ans;
en;
}
Compilation message (stderr)
dango_maker.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
52 | main()
| ^~~~
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:57:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen(name ".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:58:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen(name ".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |