///
/// You fell for it, fool!
/// Thunder Cross Split Attack!
///
#include <bits/stdc++.h>
#define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x)
typedef long long ll;
typedef std::pair<int,int> pii;
using namespace std;
const int N = 3009;
int ch, cv;
char a[N][N];
int n, m;
int mch[N*N];
pair<int,int> par[N*N];
bitset<N*N> vis;
vector<int> dard;
bool gdh(int i, int j){return 0 <= i && i < n && 0 <= j && j+3 <= m && a[i][j] == 'R' && a[i][j+1] == 'G' && a[i][j+2] == 'W';}
bool gdv(int i, int j){return 0 <= i && i+2 <= n && 0 <= j && j < m && a[i][j] == 'R' && a[i+1][j] == 'G' && a[i+2][j] == 'W';}
bool bfs(int s)
{
par[s] = {-1, -1};
vector<int> q;
q.push_back(s); vis[s] = 1;
for(int i = 0; i < q.size(); ++i)
{
auto v = q[i];
Loop(i,0,3)
{
if(!gdv(v/N-i,v%N+i)) continue;
int u = v-i*(N-1);
if(mch[u] == -1){
while(v != -1){
mch[u] = v;
u = par[v].second;
v = par[v].first;
}
for(int z : q) vis[z] = 0;
return 1;
}
if(vis[mch[u]]) continue;
q.push_back(mch[u]);
vis[mch[u]] = 1;
par[mch[u]] = {v, u};
}
}
return 0;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
Loop(i,0,n) cin >> a[i];
int ans = 0;
Loop(i,0,n) Loop(j,0,m) {
if(gdh(i,j)) dard.push_back(N*i+j);
if(gdv(i,j)) ++ans;
}
ans += dard.size();
srand(time(0));
random_shuffle(dard.begin(), dard.end());
memset(mch, -1, sizeof mch);
for(int v : dard)
{
ans -= bfs(v);
}
cout << ans << '\n';
}
Compilation message
dango_maker.cpp: In function 'bool bfs(int)':
dango_maker.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i = 0; i < q.size(); ++i)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
35660 KB |
Output is correct |
2 |
Correct |
13 ms |
35688 KB |
Output is correct |
3 |
Correct |
13 ms |
35716 KB |
Output is correct |
4 |
Correct |
14 ms |
35672 KB |
Output is correct |
5 |
Correct |
16 ms |
35660 KB |
Output is correct |
6 |
Correct |
14 ms |
35688 KB |
Output is correct |
7 |
Correct |
13 ms |
35660 KB |
Output is correct |
8 |
Correct |
14 ms |
35660 KB |
Output is correct |
9 |
Correct |
13 ms |
35704 KB |
Output is correct |
10 |
Correct |
14 ms |
35684 KB |
Output is correct |
11 |
Correct |
14 ms |
35704 KB |
Output is correct |
12 |
Correct |
14 ms |
35736 KB |
Output is correct |
13 |
Correct |
14 ms |
35784 KB |
Output is correct |
14 |
Correct |
12 ms |
35660 KB |
Output is correct |
15 |
Correct |
14 ms |
35664 KB |
Output is correct |
16 |
Correct |
15 ms |
35660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
35660 KB |
Output is correct |
2 |
Correct |
13 ms |
35688 KB |
Output is correct |
3 |
Correct |
13 ms |
35716 KB |
Output is correct |
4 |
Correct |
14 ms |
35672 KB |
Output is correct |
5 |
Correct |
16 ms |
35660 KB |
Output is correct |
6 |
Correct |
14 ms |
35688 KB |
Output is correct |
7 |
Correct |
13 ms |
35660 KB |
Output is correct |
8 |
Correct |
14 ms |
35660 KB |
Output is correct |
9 |
Correct |
13 ms |
35704 KB |
Output is correct |
10 |
Correct |
14 ms |
35684 KB |
Output is correct |
11 |
Correct |
14 ms |
35704 KB |
Output is correct |
12 |
Correct |
14 ms |
35736 KB |
Output is correct |
13 |
Correct |
14 ms |
35784 KB |
Output is correct |
14 |
Correct |
12 ms |
35660 KB |
Output is correct |
15 |
Correct |
14 ms |
35664 KB |
Output is correct |
16 |
Correct |
15 ms |
35660 KB |
Output is correct |
17 |
Correct |
13 ms |
35788 KB |
Output is correct |
18 |
Correct |
14 ms |
35788 KB |
Output is correct |
19 |
Correct |
14 ms |
35756 KB |
Output is correct |
20 |
Correct |
18 ms |
35788 KB |
Output is correct |
21 |
Correct |
14 ms |
35788 KB |
Output is correct |
22 |
Correct |
16 ms |
35708 KB |
Output is correct |
23 |
Correct |
13 ms |
35692 KB |
Output is correct |
24 |
Correct |
13 ms |
35788 KB |
Output is correct |
25 |
Correct |
13 ms |
35788 KB |
Output is correct |
26 |
Correct |
14 ms |
35644 KB |
Output is correct |
27 |
Correct |
13 ms |
35748 KB |
Output is correct |
28 |
Correct |
14 ms |
35744 KB |
Output is correct |
29 |
Correct |
14 ms |
35840 KB |
Output is correct |
30 |
Correct |
14 ms |
35696 KB |
Output is correct |
31 |
Correct |
14 ms |
35788 KB |
Output is correct |
32 |
Correct |
17 ms |
35788 KB |
Output is correct |
33 |
Correct |
16 ms |
35840 KB |
Output is correct |
34 |
Correct |
14 ms |
35780 KB |
Output is correct |
35 |
Correct |
15 ms |
35788 KB |
Output is correct |
36 |
Correct |
13 ms |
35788 KB |
Output is correct |
37 |
Correct |
13 ms |
35808 KB |
Output is correct |
38 |
Correct |
15 ms |
35788 KB |
Output is correct |
39 |
Correct |
14 ms |
35756 KB |
Output is correct |
40 |
Correct |
13 ms |
35788 KB |
Output is correct |
41 |
Correct |
13 ms |
35788 KB |
Output is correct |
42 |
Correct |
13 ms |
35788 KB |
Output is correct |
43 |
Correct |
14 ms |
35788 KB |
Output is correct |
44 |
Correct |
13 ms |
35788 KB |
Output is correct |
45 |
Correct |
13 ms |
35736 KB |
Output is correct |
46 |
Correct |
14 ms |
35788 KB |
Output is correct |
47 |
Correct |
14 ms |
35788 KB |
Output is correct |
48 |
Correct |
15 ms |
35792 KB |
Output is correct |
49 |
Correct |
14 ms |
35788 KB |
Output is correct |
50 |
Correct |
13 ms |
35788 KB |
Output is correct |
51 |
Correct |
14 ms |
35700 KB |
Output is correct |
52 |
Correct |
13 ms |
35724 KB |
Output is correct |
53 |
Correct |
14 ms |
35788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
35660 KB |
Output is correct |
2 |
Correct |
13 ms |
35688 KB |
Output is correct |
3 |
Correct |
13 ms |
35716 KB |
Output is correct |
4 |
Correct |
14 ms |
35672 KB |
Output is correct |
5 |
Correct |
16 ms |
35660 KB |
Output is correct |
6 |
Correct |
14 ms |
35688 KB |
Output is correct |
7 |
Correct |
13 ms |
35660 KB |
Output is correct |
8 |
Correct |
14 ms |
35660 KB |
Output is correct |
9 |
Correct |
13 ms |
35704 KB |
Output is correct |
10 |
Correct |
14 ms |
35684 KB |
Output is correct |
11 |
Correct |
14 ms |
35704 KB |
Output is correct |
12 |
Correct |
14 ms |
35736 KB |
Output is correct |
13 |
Correct |
14 ms |
35784 KB |
Output is correct |
14 |
Correct |
12 ms |
35660 KB |
Output is correct |
15 |
Correct |
14 ms |
35664 KB |
Output is correct |
16 |
Correct |
15 ms |
35660 KB |
Output is correct |
17 |
Correct |
13 ms |
35788 KB |
Output is correct |
18 |
Correct |
14 ms |
35788 KB |
Output is correct |
19 |
Correct |
14 ms |
35756 KB |
Output is correct |
20 |
Correct |
18 ms |
35788 KB |
Output is correct |
21 |
Correct |
14 ms |
35788 KB |
Output is correct |
22 |
Correct |
16 ms |
35708 KB |
Output is correct |
23 |
Correct |
13 ms |
35692 KB |
Output is correct |
24 |
Correct |
13 ms |
35788 KB |
Output is correct |
25 |
Correct |
13 ms |
35788 KB |
Output is correct |
26 |
Correct |
14 ms |
35644 KB |
Output is correct |
27 |
Correct |
13 ms |
35748 KB |
Output is correct |
28 |
Correct |
14 ms |
35744 KB |
Output is correct |
29 |
Correct |
14 ms |
35840 KB |
Output is correct |
30 |
Correct |
14 ms |
35696 KB |
Output is correct |
31 |
Correct |
14 ms |
35788 KB |
Output is correct |
32 |
Correct |
17 ms |
35788 KB |
Output is correct |
33 |
Correct |
16 ms |
35840 KB |
Output is correct |
34 |
Correct |
14 ms |
35780 KB |
Output is correct |
35 |
Correct |
15 ms |
35788 KB |
Output is correct |
36 |
Correct |
13 ms |
35788 KB |
Output is correct |
37 |
Correct |
13 ms |
35808 KB |
Output is correct |
38 |
Correct |
15 ms |
35788 KB |
Output is correct |
39 |
Correct |
14 ms |
35756 KB |
Output is correct |
40 |
Correct |
13 ms |
35788 KB |
Output is correct |
41 |
Correct |
13 ms |
35788 KB |
Output is correct |
42 |
Correct |
13 ms |
35788 KB |
Output is correct |
43 |
Correct |
14 ms |
35788 KB |
Output is correct |
44 |
Correct |
13 ms |
35788 KB |
Output is correct |
45 |
Correct |
13 ms |
35736 KB |
Output is correct |
46 |
Correct |
14 ms |
35788 KB |
Output is correct |
47 |
Correct |
14 ms |
35788 KB |
Output is correct |
48 |
Correct |
15 ms |
35792 KB |
Output is correct |
49 |
Correct |
14 ms |
35788 KB |
Output is correct |
50 |
Correct |
13 ms |
35788 KB |
Output is correct |
51 |
Correct |
14 ms |
35700 KB |
Output is correct |
52 |
Correct |
13 ms |
35724 KB |
Output is correct |
53 |
Correct |
14 ms |
35788 KB |
Output is correct |
54 |
Correct |
14 ms |
35708 KB |
Output is correct |
55 |
Correct |
17 ms |
44488 KB |
Output is correct |
56 |
Correct |
14 ms |
35844 KB |
Output is correct |
57 |
Correct |
18 ms |
47396 KB |
Output is correct |
58 |
Correct |
38 ms |
50840 KB |
Output is correct |
59 |
Correct |
246 ms |
117752 KB |
Output is correct |
60 |
Correct |
233 ms |
117860 KB |
Output is correct |
61 |
Correct |
228 ms |
117736 KB |
Output is correct |
62 |
Correct |
13 ms |
35740 KB |
Output is correct |
63 |
Correct |
220 ms |
117768 KB |
Output is correct |
64 |
Correct |
1149 ms |
137148 KB |
Output is correct |
65 |
Correct |
1184 ms |
136952 KB |
Output is correct |
66 |
Correct |
1255 ms |
136976 KB |
Output is correct |
67 |
Correct |
74 ms |
53316 KB |
Output is correct |
68 |
Correct |
75 ms |
53648 KB |
Output is correct |
69 |
Correct |
82 ms |
65220 KB |
Output is correct |
70 |
Correct |
97 ms |
53176 KB |
Output is correct |
71 |
Correct |
102 ms |
53304 KB |
Output is correct |
72 |
Correct |
96 ms |
53232 KB |
Output is correct |
73 |
Correct |
96 ms |
53176 KB |
Output is correct |
74 |
Correct |
104 ms |
53184 KB |
Output is correct |
75 |
Correct |
104 ms |
53244 KB |
Output is correct |
76 |
Correct |
121 ms |
53252 KB |
Output is correct |
77 |
Correct |
97 ms |
53208 KB |
Output is correct |
78 |
Correct |
104 ms |
53236 KB |
Output is correct |
79 |
Correct |
98 ms |
53220 KB |
Output is correct |
80 |
Correct |
100 ms |
53184 KB |
Output is correct |
81 |
Correct |
100 ms |
53248 KB |
Output is correct |
82 |
Correct |
102 ms |
53184 KB |
Output is correct |
83 |
Correct |
133 ms |
53300 KB |
Output is correct |
84 |
Correct |
102 ms |
53196 KB |
Output is correct |
85 |
Correct |
100 ms |
53180 KB |
Output is correct |
86 |
Correct |
106 ms |
53176 KB |
Output is correct |
87 |
Correct |
103 ms |
53188 KB |
Output is correct |
88 |
Correct |
105 ms |
53176 KB |
Output is correct |
89 |
Correct |
101 ms |
53180 KB |
Output is correct |
90 |
Correct |
102 ms |
53176 KB |
Output is correct |