#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
int m,n,ans;
char c[N][N];
int v[N][N],h[N][N];
int cv[N][N],ch[N][N];
set<tuple<int,int,int,int> > s;
void del(tuple<int,int,int,int> a,tuple<int,int,int,int> tt)
{
auto [c,x,y,t] = a;
if(t==0)
{
auto it = s.find({ch[x-2][y+2],x-2,y+2,1});
if(it!=s.end() and *it!=tt) ch[x-2][y+2]--,s.erase(it),s.insert({ch[x-2][y+2],x-2,y+2,1});
it = s.find({ch[x-1][y+1],x-1,y+1,1});
if(it!=s.end() and *it!=tt) ch[x-1][y+1]--,s.erase(it),s.insert({ch[x-1][y+1],x-1,y+1,1});
it = s.find({ch[x][y],x,y,1});
if(it!=s.end() and *it!=tt) ch[x][y]--,s.erase(it),s.insert({ch[x][y],x,y,1});
}
else
{
auto it = s.find({cv[x+2][y-2],x+2,y-2,0});
if(it!=s.end() and *it!=tt) cv[x+2][y-2]--,s.erase(it),s.insert({cv[x+2][y-2],x+2,y-2,0});
it = s.find({cv[x+1][y-1],x+1,y-1,0});
if(it!=s.end() and *it!=tt) cv[x+1][y-1]--,s.erase(it),s.insert({cv[x+1][y-1],x+1,y-1,0});
it = s.find({cv[x][y],x,y,0});
if(it!=s.end() and *it!=tt) cv[x][y]--,s.erase(it),s.insert({cv[x][y],x,y,0});
}
s.erase({c,x,y,t});
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> m >> n;
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++) cin >> c[i][j];
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++)
{
if(i>2 and c[i-2][j]=='R' and c[i-1][j]=='G' and c[i][j]=='W') v[i][j] = 1;
if(j>2 and c[i][j-2]=='R' and c[i][j-1]=='G' and c[i][j]=='W') h[i][j] = 1;
}
for(int i = 1;i <= m;i++) for(int j = 1;j <= n;j++)
{
if(v[i][j]) cv[i][j] = h[i][j]+h[i-1][j+1]+h[i-2][j+2],s.insert({cv[i][j],i,j,0});
if(h[i][j]) ch[i][j] = v[i][j]+v[i+1][j-1]+v[i+2][j-2],s.insert({ch[i][j],i,j,1});
}
while(!s.empty())
{
tuple<int,int,int,int> tt = (*s.begin());
auto [c,x,y,t] = tt;
ans++;
if(t==0)
{
auto it = s.find({ch[x-2][y+2],x-2,y+2,1});
if(it!=s.end()) del({ch[x-2][y+2],x-2,y+2,1},tt);
it = s.find({ch[x-1][y+1],x-1,y+1,1});
if(it!=s.end()) del({ch[x-1][y+1],x-1,y+1,1},tt);
it = s.find({ch[x][y],x,y,1});
if(it!=s.end()) del({ch[x][y],x,y,1},tt);
}
else
{
auto it = s.find({cv[x+2][y-2],x+2,y-2,0});
if(it!=s.end()) del({cv[x+2][y-2],x+2,y-2,0},tt);
it = s.find({cv[x+1][y-1],x+1,y-1,0});
if(it!=s.end()) del({cv[x+1][y-1],x+1,y-1,0},tt);
it = s.find({cv[x][y],x,y,0});
if(it!=s.end()) del({cv[x][y],x,y,0},tt);
}
s.erase({c,x,y,t});
}
cout << ans;
}
Compilation message
dango_maker.cpp: In function 'void del(std::tuple<int, int, int, int>, std::tuple<int, int, int, int>)':
dango_maker.cpp:14:10: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [c,x,y,t] = a;
^
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:55:14: warning: decomposition declaration only available with -std=c++1z or -std=gnu++1z
auto [c,x,y,t] = tt;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
512 KB |
Output is correct |
34 |
Correct |
5 ms |
512 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
36 |
Correct |
5 ms |
512 KB |
Output is correct |
37 |
Correct |
5 ms |
512 KB |
Output is correct |
38 |
Correct |
5 ms |
512 KB |
Output is correct |
39 |
Correct |
5 ms |
512 KB |
Output is correct |
40 |
Correct |
5 ms |
512 KB |
Output is correct |
41 |
Correct |
5 ms |
512 KB |
Output is correct |
42 |
Correct |
5 ms |
512 KB |
Output is correct |
43 |
Correct |
5 ms |
512 KB |
Output is correct |
44 |
Correct |
5 ms |
512 KB |
Output is correct |
45 |
Correct |
5 ms |
512 KB |
Output is correct |
46 |
Correct |
6 ms |
512 KB |
Output is correct |
47 |
Correct |
6 ms |
512 KB |
Output is correct |
48 |
Correct |
5 ms |
512 KB |
Output is correct |
49 |
Correct |
5 ms |
512 KB |
Output is correct |
50 |
Correct |
5 ms |
512 KB |
Output is correct |
51 |
Correct |
5 ms |
512 KB |
Output is correct |
52 |
Correct |
5 ms |
512 KB |
Output is correct |
53 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
512 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
512 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
4 ms |
384 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |
33 |
Correct |
5 ms |
512 KB |
Output is correct |
34 |
Correct |
5 ms |
512 KB |
Output is correct |
35 |
Correct |
5 ms |
512 KB |
Output is correct |
36 |
Correct |
5 ms |
512 KB |
Output is correct |
37 |
Correct |
5 ms |
512 KB |
Output is correct |
38 |
Correct |
5 ms |
512 KB |
Output is correct |
39 |
Correct |
5 ms |
512 KB |
Output is correct |
40 |
Correct |
5 ms |
512 KB |
Output is correct |
41 |
Correct |
5 ms |
512 KB |
Output is correct |
42 |
Correct |
5 ms |
512 KB |
Output is correct |
43 |
Correct |
5 ms |
512 KB |
Output is correct |
44 |
Correct |
5 ms |
512 KB |
Output is correct |
45 |
Correct |
5 ms |
512 KB |
Output is correct |
46 |
Correct |
6 ms |
512 KB |
Output is correct |
47 |
Correct |
6 ms |
512 KB |
Output is correct |
48 |
Correct |
5 ms |
512 KB |
Output is correct |
49 |
Correct |
5 ms |
512 KB |
Output is correct |
50 |
Correct |
5 ms |
512 KB |
Output is correct |
51 |
Correct |
5 ms |
512 KB |
Output is correct |
52 |
Correct |
5 ms |
512 KB |
Output is correct |
53 |
Correct |
5 ms |
512 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
13 ms |
10240 KB |
Output is correct |
56 |
Correct |
6 ms |
768 KB |
Output is correct |
57 |
Correct |
21 ms |
26496 KB |
Output is correct |
58 |
Correct |
99 ms |
39416 KB |
Output is correct |
59 |
Correct |
728 ms |
192888 KB |
Output is correct |
60 |
Correct |
743 ms |
192888 KB |
Output is correct |
61 |
Correct |
719 ms |
192632 KB |
Output is correct |
62 |
Correct |
6 ms |
384 KB |
Output is correct |
63 |
Correct |
722 ms |
191352 KB |
Output is correct |
64 |
Runtime error |
767 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |