#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define INF 100000000000000000
//#define int long long
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
#define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
int n, m;
const int N = 3000;//first->horizontal, second -> vertical
vector<bool> vis;
vector<vector<int>> adj;
int currnode = 0;
int solve(int i){
vector<int> lvls;
queue<pair<int, int>> q;
q.push({i, 0});
vis[i] = true;
while(!q.empty()){
pair<int, int> curr = q.front();
q.pop();
if(lvls.size()<=curr.second) lvls.push_back(1);
else lvls[curr.second]++;
for(int j: adj[curr.first]){
if(vis[j]) continue;
vis[j] = true;
q.push({j, curr.second + 1});
}
}
if(lvls.size()==1) return lvls[0];
if(lvls.size()==2) return max(lvls[0], lvls[1]);
pair<int, int> dp = {lvls[0], lvls[1]};
int tr = max(dp.first, dp.second);
for(int i = 2;i<lvls.size();i++){
int temp = max(dp.first + lvls[i], dp.second);
dp.first = dp.second;
dp.second = temp;
tr = max(tr, temp);
}
return tr;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
char mat[n][m];
pair<int, int> nodenum[n][m];
for(int i = 0;i<n;i++){
string s;
for(int j = 0;j<m;j++) cin>>mat[i][j];
}
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++) nodenum[i][j] = {-1, -1};
}
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
if(mat[i][j]!='R') continue;
if(i+2<n){
if(mat[i+1][j]=='G' && mat[i+2][j]=='W'){
int cnode = currnode++;
vis.push_back(false);
adj.push_back({});
//cout<<cnode<<" is ("<<i<<", "<<j<<") vertical"<<endl;
nodenum[i][j].second = cnode;
/*if(nodenum[i][j].first != -1){
adj[nodenum[i][j].first].insert(cnode);
adj[cnode].insert(nodenum[i][j].first);
}
if(j>0 && nodenum[i+1][j-1].first!=-1){
adj[nodenum[i+1][j-1].first].insert(cnode);
adj[cnode].insert(nodenum[i+1][j-1].first);
}
if(j>1 && nodenum[i+2][j-2].first!=-1){
adj[nodenum[i+2][j-2].first].insert(cnode);
adj[cnode].insert(nodenum[i+2][j-2].first);
}*/
}
}
if(j+2<m){
if(mat[i][j+1]=='G' && mat[i][j+2]=='W'){
int cnode = currnode++;
vis.push_back(false);
adj.push_back({});
//cout<<cnode<<" is ("<<i<<", "<<j<<") horizontal"<<endl;
nodenum[i][j].first = cnode;
if(nodenum[i][j].second != -1){
adj[nodenum[i][j].second].push_back(cnode);
adj[cnode].push_back(nodenum[i][j].second);
}
if(i>0 && nodenum[i-1][j+1].second!=-1){
adj[nodenum[i-1][j+1].second].push_back(cnode);
adj[cnode].push_back(nodenum[i-1][j+1].second);
}
if(i>1 && nodenum[i-2][j+2].second!=-1){
adj[nodenum[i-2][j+2].second].push_back(cnode);
adj[cnode].push_back(nodenum[i-2][j+2].second);
}
}
}
}
}
int ans = 0;
for(int i = 0;i<currnode;i++){
/*cout<<i<<" is connected to: ";
for(int j: adj[i]){
cout<<j<<" ";
}
cout<<endl;
*/
if(!vis[i]){
ans+=solve(i);
}
}
cout<<ans<<endl;
//create a node out of each skewer that you can make
//connect nodes that intersect with each other
//For each connected component,
}
/*
4 4
RGWR
GRRG
WGGW
WWWR
5 5
RGRGW
GRRGW
WGGWR
RWRGW
RGWGW
*/
Compilation message
dango_maker.cpp: In function 'int solve(int)':
dango_maker.cpp:27:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(lvls.size()<=curr.second) lvls.push_back(1);
~~~~~~~~~~~^~~~~~~~~~~~~
dango_maker.cpp:39:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 2;i<lvls.size();i++){
~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 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 |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
256 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
4 ms |
384 KB |
Output is correct |
45 |
Correct |
4 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
4 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 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 |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
4 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
5 ms |
384 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 |
384 KB |
Output is correct |
34 |
Correct |
5 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
4 ms |
384 KB |
Output is correct |
37 |
Correct |
4 ms |
384 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
4 ms |
384 KB |
Output is correct |
40 |
Correct |
5 ms |
256 KB |
Output is correct |
41 |
Correct |
5 ms |
384 KB |
Output is correct |
42 |
Correct |
5 ms |
384 KB |
Output is correct |
43 |
Correct |
5 ms |
384 KB |
Output is correct |
44 |
Correct |
4 ms |
384 KB |
Output is correct |
45 |
Correct |
4 ms |
384 KB |
Output is correct |
46 |
Correct |
5 ms |
384 KB |
Output is correct |
47 |
Correct |
5 ms |
384 KB |
Output is correct |
48 |
Correct |
5 ms |
384 KB |
Output is correct |
49 |
Correct |
5 ms |
384 KB |
Output is correct |
50 |
Correct |
5 ms |
384 KB |
Output is correct |
51 |
Correct |
4 ms |
384 KB |
Output is correct |
52 |
Correct |
5 ms |
384 KB |
Output is correct |
53 |
Correct |
4 ms |
384 KB |
Output is correct |
54 |
Correct |
5 ms |
384 KB |
Output is correct |
55 |
Correct |
5 ms |
384 KB |
Output is correct |
56 |
Correct |
6 ms |
640 KB |
Output is correct |
57 |
Correct |
6 ms |
640 KB |
Output is correct |
58 |
Correct |
48 ms |
12956 KB |
Output is correct |
59 |
Correct |
390 ms |
109292 KB |
Output is correct |
60 |
Correct |
397 ms |
109320 KB |
Output is correct |
61 |
Correct |
395 ms |
109296 KB |
Output is correct |
62 |
Correct |
5 ms |
384 KB |
Output is correct |
63 |
Correct |
372 ms |
106608 KB |
Output is correct |
64 |
Runtime error |
819 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |