#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define mp make_pair
#define f first
#define s second
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 3e3+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
namespace io {
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
// cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
if (sz(s)) {
setIn(s+".in");
setOut(s+".out");
} // for USACO
}
}
using namespace io;
namespace input {
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class T> void re(T& x) { cin >> x; }
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
re(first); re(rest...);
}
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}
namespace output {
template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
pr("{",x.f,", ",x.s,"}");
}
template<class T> void prContain(const T& x) {
pr("{");
bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
void ps() { pr("\n"); }
template<class Arg> void ps(const Arg& first) {
pr(first); ps(); // no space at end of line
}
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
pr(first," "); ps(rest...); // print w/ spaces
}
}
using namespace output;
using namespace input;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
// 0-2 cooldown on the right dumplings
// 3-5 cooldown on the down dumplings (subtract 3)
char grid[MX][MX];
ll N, M;
vector<pair<bool, bool>> diagonals[2*MX];
bool inBounds(ll i, ll j) {
if (i >= 0 && j >= 0 && i < N && j < M) {
return true;
} else {
return false;
}
}
int main() {
setIO();
re(N, M);
F0R (i, N) {
F0R (j, M) {
re(grid[i][j]);
}
}
F0R (col, M) {
ll i = 0, j = col;
do {
bool goright = false, godown = false;
if (j + 2 < M && grid[i][j] == 'R' && grid[i][j+1] == 'G' && grid[i][j+2] == 'W') {
goright = true;
}
if (i + 2 < N && grid[i][j] == 'R' && grid[i+1][j] == 'G' && grid[i+2][j] == 'W') {
godown = true;
}
i++;
j--;
diagonals[col].pb({goright, godown});
} while (inBounds(i, j));
}
F0R (row, N) {
if (row == 0) {
continue;
}
ll i = row, j = M-1;
do {
bool goright = false, godown = false;
if (j + 2 < M && grid[i][j] == 'R' && grid[i][j+1] == 'G' && grid[i][j+2] == 'W') {
goright = true;
}
if (i + 2 < N && grid[i][j] == 'R' && grid[i+1][j] == 'G' && grid[i+2][j] == 'W') {
godown = true;
}
i++;
j--;
diagonals[M+row-1].pb({goright, godown});
} while (inBounds(i, j));
}
ll ans = 0;
F0R (col, M+N-1) {
vector<vector<ll>> dp(diagonals[col].size()+1, vector<ll>(3, 0));
ll auxbest = 0;
R0F (i, diagonals[col].size()) {
F0R (j, 3) {
if (diagonals[col][i].f && j == 0) {
dp[i][j] = max(dp[i][j], 1+dp[i+1][j]);
}
if (diagonals[col][i].s) {
dp[i][j] = max(dp[i][j], 1+dp[i+1][2]);
}
dp[i][j] = max(dp[i][j], dp[i+1][max(0, j-1)]);
auxbest = max(auxbest, dp[i][j]);
}
}
ans+=auxbest;
}
ps(ans);
return 0;
}
/*
F0R (col, M) {
vector<vector<vector<ll>>> dp(diagonals[col].size()+1, vector<vector<ll>>(3, vector<ll>(3, 0)));
ll auxbest = 0;
R0F (i, diagonals[col].size()) {
F0R (j, 3) {
F0R (k, 3) {
if (diagonals[col][i].f && j == 0) {
dp[i][j][k] = max(dp[i][j][k], 1+dp[i][j][2]);
}
if (diagonals[col][i].s && k == 0) {
dp[i][j][k] = max(dp[i][j][k], 1+dp[i][2][k]);
}
dp[i][j][k] = max(dp[i][j][k], dp[i][max(j-1, 0)][max(k-1, 0)]);
auxbest = max(auxbest, dp[i][j][k]);
}
}
}
}
*/
Compilation message
dango_maker.cpp: In function 'void io::setIn(std::string)':
dango_maker.cpp:67:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
67 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp: In function 'void io::setOut(std::string)':
dango_maker.cpp:68:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
68 | void setOut(string s) { freopen(s.c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
0 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
0 ms |
512 KB |
Output is correct |
26 |
Correct |
0 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
0 ms |
512 KB |
Output is correct |
29 |
Correct |
0 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
0 ms |
512 KB |
Output is correct |
32 |
Correct |
0 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
512 KB |
Output is correct |
34 |
Correct |
0 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
0 ms |
512 KB |
Output is correct |
40 |
Correct |
0 ms |
512 KB |
Output is correct |
41 |
Correct |
0 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
0 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
0 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
0 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
0 ms |
512 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
0 ms |
512 KB |
Output is correct |
10 |
Correct |
0 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
1 ms |
512 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
0 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
0 ms |
512 KB |
Output is correct |
26 |
Correct |
0 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
0 ms |
512 KB |
Output is correct |
29 |
Correct |
0 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
0 ms |
512 KB |
Output is correct |
32 |
Correct |
0 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
512 KB |
Output is correct |
34 |
Correct |
0 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
0 ms |
512 KB |
Output is correct |
40 |
Correct |
0 ms |
512 KB |
Output is correct |
41 |
Correct |
0 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
0 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
0 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
0 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
1 ms |
512 KB |
Output is correct |
54 |
Correct |
1 ms |
640 KB |
Output is correct |
55 |
Correct |
6 ms |
9344 KB |
Output is correct |
56 |
Correct |
2 ms |
640 KB |
Output is correct |
57 |
Correct |
6 ms |
6400 KB |
Output is correct |
58 |
Correct |
91 ms |
6136 KB |
Output is correct |
59 |
Correct |
828 ms |
36000 KB |
Output is correct |
60 |
Correct |
813 ms |
44668 KB |
Output is correct |
61 |
Correct |
825 ms |
44928 KB |
Output is correct |
62 |
Correct |
1 ms |
640 KB |
Output is correct |
63 |
Correct |
786 ms |
43620 KB |
Output is correct |
64 |
Correct |
780 ms |
44804 KB |
Output is correct |
65 |
Correct |
776 ms |
44688 KB |
Output is correct |
66 |
Correct |
811 ms |
44668 KB |
Output is correct |
67 |
Correct |
793 ms |
44624 KB |
Output is correct |
68 |
Correct |
798 ms |
44752 KB |
Output is correct |
69 |
Correct |
809 ms |
44668 KB |
Output is correct |
70 |
Correct |
91 ms |
7160 KB |
Output is correct |
71 |
Correct |
89 ms |
7160 KB |
Output is correct |
72 |
Correct |
90 ms |
7288 KB |
Output is correct |
73 |
Correct |
89 ms |
7160 KB |
Output is correct |
74 |
Correct |
90 ms |
7288 KB |
Output is correct |
75 |
Correct |
88 ms |
7160 KB |
Output is correct |
76 |
Correct |
90 ms |
7160 KB |
Output is correct |
77 |
Correct |
90 ms |
7288 KB |
Output is correct |
78 |
Correct |
106 ms |
7288 KB |
Output is correct |
79 |
Correct |
92 ms |
7160 KB |
Output is correct |
80 |
Correct |
88 ms |
7160 KB |
Output is correct |
81 |
Correct |
89 ms |
7288 KB |
Output is correct |
82 |
Correct |
91 ms |
7160 KB |
Output is correct |
83 |
Correct |
89 ms |
7160 KB |
Output is correct |
84 |
Correct |
93 ms |
7288 KB |
Output is correct |
85 |
Correct |
90 ms |
7160 KB |
Output is correct |
86 |
Correct |
92 ms |
7288 KB |
Output is correct |
87 |
Correct |
91 ms |
7160 KB |
Output is correct |
88 |
Correct |
88 ms |
7160 KB |
Output is correct |
89 |
Correct |
88 ms |
7160 KB |
Output is correct |
90 |
Correct |
91 ms |
7288 KB |
Output is correct |