#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=3e3+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
char c[N][N];
ll dp[N][3],n,m,T[N][N],ans;
vector<ll> D[2*N];
bool valid(ll xa,ll ya,ll xb,ll yb){
if(xa>xb)swap(xa,xb);
if(ya>yb)swap(ya,yb);
ll xm=(xa+xb)/2,ym=(ya+yb)/2;
if(xa<0||xb>=n||ya<0||yb>=m||c[xm][ym]!='G')return 0;
if(ya==yb){
return ((c[xa][ym]=='R'&&c[xb][ym]=='W'));
}else{
return ((c[xm][ya]=='R'&&c[xm][yb]=='W'));
}
}
ll CAL(ll id){
memset(dp,0,sizeof(dp));
REP(i,SZ(D[id])){
dp[i+1][0]=max(dp[i][0],max(dp[i][1],dp[i][2]));
if(D[id][i]&1)dp[i+1][1]=max(dp[i][0],dp[i][1])+1;
if(D[id][i]&2)dp[i+1][2]=max(dp[i][0],dp[i][2])+1;
}
return max(dp[SZ(D[id])][0],max(dp[SZ(D[id])][1],dp[SZ(D[id])][2]));
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
REP(i,n)REP(j,m){
cin>>c[i][j];
}
REP(i,n)REP(j,m){
ll nd=i*m+j;
if(c[i][j]=='G'){
if(valid(i-1,j,i+1,j))T[i][j]|=1;
if(valid(i,j-1,i,j+1))T[i][j]|=2;
}
D[i+j].pb(T[i][j]);
}
REP(i,n+m-1){
ans+=CAL(i);
}
cout<<ans<<"\n";
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:56:6: warning: unused variable 'nd' [-Wunused-variable]
56 | ll nd=i*m+j;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
580 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 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 |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 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 |
580 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 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 |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 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 |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
640 KB |
Output is correct |
24 |
Correct |
1 ms |
536 KB |
Output is correct |
25 |
Correct |
1 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
640 KB |
Output is correct |
33 |
Correct |
1 ms |
640 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
1 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
640 KB |
Output is correct |
38 |
Correct |
1 ms |
640 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
1 ms |
640 KB |
Output is correct |
42 |
Correct |
1 ms |
640 KB |
Output is correct |
43 |
Correct |
1 ms |
640 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
768 KB |
Output is correct |
47 |
Correct |
1 ms |
640 KB |
Output is correct |
48 |
Correct |
1 ms |
640 KB |
Output is correct |
49 |
Correct |
1 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
640 KB |
Output is correct |
51 |
Correct |
1 ms |
640 KB |
Output is correct |
52 |
Correct |
1 ms |
640 KB |
Output is correct |
53 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
580 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 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 |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 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 |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
640 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
640 KB |
Output is correct |
24 |
Correct |
1 ms |
536 KB |
Output is correct |
25 |
Correct |
1 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
640 KB |
Output is correct |
33 |
Correct |
1 ms |
640 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
1 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
640 KB |
Output is correct |
38 |
Correct |
1 ms |
640 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
1 ms |
640 KB |
Output is correct |
42 |
Correct |
1 ms |
640 KB |
Output is correct |
43 |
Correct |
1 ms |
640 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
768 KB |
Output is correct |
47 |
Correct |
1 ms |
640 KB |
Output is correct |
48 |
Correct |
1 ms |
640 KB |
Output is correct |
49 |
Correct |
1 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
640 KB |
Output is correct |
51 |
Correct |
1 ms |
640 KB |
Output is correct |
52 |
Correct |
1 ms |
640 KB |
Output is correct |
53 |
Correct |
1 ms |
640 KB |
Output is correct |
54 |
Correct |
8 ms |
640 KB |
Output is correct |
55 |
Correct |
17 ms |
9984 KB |
Output is correct |
56 |
Correct |
9 ms |
896 KB |
Output is correct |
57 |
Correct |
16 ms |
13696 KB |
Output is correct |
58 |
Correct |
60 ms |
26744 KB |
Output is correct |
59 |
Correct |
483 ms |
181536 KB |
Output is correct |
60 |
Correct |
473 ms |
181368 KB |
Output is correct |
61 |
Correct |
472 ms |
181368 KB |
Output is correct |
62 |
Correct |
8 ms |
640 KB |
Output is correct |
63 |
Correct |
456 ms |
178040 KB |
Output is correct |
64 |
Correct |
484 ms |
181368 KB |
Output is correct |
65 |
Correct |
473 ms |
181444 KB |
Output is correct |
66 |
Correct |
488 ms |
181424 KB |
Output is correct |
67 |
Correct |
418 ms |
138424 KB |
Output is correct |
68 |
Correct |
419 ms |
138448 KB |
Output is correct |
69 |
Correct |
416 ms |
145224 KB |
Output is correct |
70 |
Correct |
49 ms |
26872 KB |
Output is correct |
71 |
Correct |
53 ms |
26872 KB |
Output is correct |
72 |
Correct |
50 ms |
26872 KB |
Output is correct |
73 |
Correct |
51 ms |
26912 KB |
Output is correct |
74 |
Correct |
51 ms |
26872 KB |
Output is correct |
75 |
Correct |
50 ms |
26940 KB |
Output is correct |
76 |
Correct |
63 ms |
26872 KB |
Output is correct |
77 |
Correct |
50 ms |
26872 KB |
Output is correct |
78 |
Correct |
51 ms |
26880 KB |
Output is correct |
79 |
Correct |
52 ms |
26880 KB |
Output is correct |
80 |
Correct |
51 ms |
26984 KB |
Output is correct |
81 |
Correct |
51 ms |
26872 KB |
Output is correct |
82 |
Correct |
51 ms |
26872 KB |
Output is correct |
83 |
Correct |
51 ms |
27000 KB |
Output is correct |
84 |
Correct |
57 ms |
26872 KB |
Output is correct |
85 |
Correct |
63 ms |
26872 KB |
Output is correct |
86 |
Correct |
54 ms |
26872 KB |
Output is correct |
87 |
Correct |
50 ms |
26872 KB |
Output is correct |
88 |
Correct |
50 ms |
26964 KB |
Output is correct |
89 |
Correct |
50 ms |
26872 KB |
Output is correct |
90 |
Correct |
50 ms |
26980 KB |
Output is correct |