#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
void usaco(string s){
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
struct UF {
vi e;
UF(int n) : e(n, -1) {}
bool sameSet(int a, int b) { return find(a) == find(b); }
int size(int x) { return -e[find(x)]; }
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
};
const int MN = 3e3+5, MOD = 1e9+7;
char grid[MN][MN];
bool ver[MN][MN], hor[MN][MN];
int dp[MN][MN][3];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
/*
int n, m;
cin >> n >> m;
memset(vis, 0, sizeof vis);
for(int i = 0; i < n+10; i++) for(int j = 0; j < m+10; j++) grid[i][j] = '-';
for(int i = 3; i < n+3; i++) for(int j = 3; j < m+3; j++) cin >> grid[i][j];
vector<pair<int, int>> adj;
for(int i = 3; i < n+3; i++){
for(int j = 3; j < n+3; j++){
if(grid[i][j] == 'R'){
adj.push_back({i, j});
}
}
}
UF uf1, uf2;
for(auto i: adj){
//process the connected components
vector<int>().swap(proc);
if(!vis[i.first][i.second]){
dfs(i);
}
for(auto j: proc){
int x = j[0], y = j[1], dir = j[2];
if(
}
}
*/
int n,m,ret = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> (grid[i] + 1);
for (int j = 1; j <= m-2; j++) if (grid[i][j] == 'R' && grid[i][j+1] == 'G' && grid[i][j+2] == 'W') {
hor[i][j+1] = 1;
}
}
for (int j = 1; j <= m; j++)
for (int i = 1; i <= n-2; i++) if (grid[i][j] == 'R' && grid[i+1][j] == 'G' && grid[i+2][j] == 'W')
ver[i+1][j] = 1;
for (int v = 2, add = 0; v <= n+m; v++, ret += add, add = 0)
for (int i = 1, j = v - i; i <= n; i++, j = v - i)
if (1 <= j && j <= m) {
dp[i][j][0] = max({dp[i-1][j+1][0],dp[i-1][j+1][1],dp[i-1][j+1][2]});
if (hor[i][j])
dp[i][j][1] = max(dp[i-1][j+1][0],dp[i-1][j+1][1]) + 1;
if (ver[i][j])
dp[i][j][2] = max(dp[i-1][j+1][0],dp[i-1][j+1][2]) + 1;
add = max({add,dp[i][j][0],dp[i][j][1],dp[i][j][2]});
}
cout << ret << '\n';
return 0;
}
Compilation message
dango_maker.cpp: In function 'void usaco(std::string)':
dango_maker.cpp:13:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
13 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dango_maker.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
14 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
400 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
400 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
1 ms |
492 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
492 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
1 ms |
492 KB |
Output is correct |
51 |
Correct |
1 ms |
492 KB |
Output is correct |
52 |
Correct |
8 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
400 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
504 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
492 KB |
Output is correct |
20 |
Correct |
1 ms |
492 KB |
Output is correct |
21 |
Correct |
1 ms |
492 KB |
Output is correct |
22 |
Correct |
1 ms |
492 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
492 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
492 KB |
Output is correct |
28 |
Correct |
1 ms |
492 KB |
Output is correct |
29 |
Correct |
1 ms |
492 KB |
Output is correct |
30 |
Correct |
1 ms |
492 KB |
Output is correct |
31 |
Correct |
1 ms |
492 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
492 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
1 ms |
492 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
492 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
1 ms |
492 KB |
Output is correct |
51 |
Correct |
1 ms |
492 KB |
Output is correct |
52 |
Correct |
8 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
492 KB |
Output is correct |
54 |
Correct |
1 ms |
364 KB |
Output is correct |
55 |
Correct |
21 ms |
21868 KB |
Output is correct |
56 |
Correct |
1 ms |
620 KB |
Output is correct |
57 |
Correct |
17 ms |
22892 KB |
Output is correct |
58 |
Correct |
56 ms |
25196 KB |
Output is correct |
59 |
Correct |
528 ms |
132972 KB |
Output is correct |
60 |
Correct |
533 ms |
132844 KB |
Output is correct |
61 |
Correct |
526 ms |
132972 KB |
Output is correct |
62 |
Correct |
1 ms |
492 KB |
Output is correct |
63 |
Correct |
515 ms |
132844 KB |
Output is correct |
64 |
Correct |
492 ms |
132844 KB |
Output is correct |
65 |
Correct |
500 ms |
132844 KB |
Output is correct |
66 |
Correct |
494 ms |
132844 KB |
Output is correct |
67 |
Correct |
450 ms |
122220 KB |
Output is correct |
68 |
Correct |
450 ms |
122228 KB |
Output is correct |
69 |
Correct |
487 ms |
128620 KB |
Output is correct |
70 |
Correct |
48 ms |
25196 KB |
Output is correct |
71 |
Correct |
51 ms |
25196 KB |
Output is correct |
72 |
Correct |
48 ms |
25196 KB |
Output is correct |
73 |
Correct |
51 ms |
25196 KB |
Output is correct |
74 |
Correct |
48 ms |
25196 KB |
Output is correct |
75 |
Correct |
49 ms |
25196 KB |
Output is correct |
76 |
Correct |
48 ms |
25196 KB |
Output is correct |
77 |
Correct |
48 ms |
25196 KB |
Output is correct |
78 |
Correct |
49 ms |
25196 KB |
Output is correct |
79 |
Correct |
48 ms |
25196 KB |
Output is correct |
80 |
Correct |
47 ms |
25196 KB |
Output is correct |
81 |
Correct |
49 ms |
25196 KB |
Output is correct |
82 |
Correct |
53 ms |
25324 KB |
Output is correct |
83 |
Correct |
49 ms |
25196 KB |
Output is correct |
84 |
Correct |
56 ms |
25196 KB |
Output is correct |
85 |
Correct |
48 ms |
25196 KB |
Output is correct |
86 |
Correct |
48 ms |
25196 KB |
Output is correct |
87 |
Correct |
49 ms |
25196 KB |
Output is correct |
88 |
Correct |
48 ms |
25196 KB |
Output is correct |
89 |
Correct |
48 ms |
25324 KB |
Output is correct |
90 |
Correct |
59 ms |
25196 KB |
Output is correct |