# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1261554 | namhh | Dango Maker (JOI18_dango_maker) | C++20 | 269 ms | 115176 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
const int N = 3e3+5;
int n,m,dp[N][N][3];
char rem[N][N];
// ga qua phai chef code huhu :<
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++) cin >> rem[i][j];
}
int ans = 0;
for(int i = 1; i <= n; i++){
int l = i;
int r = 1;
int mx = 0;
while(l >= 1 && l <= n && r >= 1 && r <= m){
dp[l][r][0] = max({dp[l+1][r-1][0],dp[l+1][r-1][1],dp[l+1][r-1][2]});
if(rem[l][r] == 'R'){
if(rem[l+1][r] == 'G' && rem[l+2][r] == 'W'){
dp[l][r][1] = dp[l+1][r-1][1];
if(r > 2) dp[l][r][1] = max({dp[l][r][1],dp[l+2][r-2][0],dp[l+2][r-2][1]});
if(r > 3) dp[l][r][1] = max({dp[l][r][1],dp[l+3][r-3][0],dp[l+3][r-3][1],dp[l+3][r-3][2]});
dp[l][r][1]++;
}
if(rem[l][r+1] == 'G' && rem[l][r+2] == 'W') dp[l][r][2] = max({dp[l+1][r-1][0],dp[l+1][r-1][1],dp[l+1][r-1][2]})+1;
}
mx = max({dp[l][r][0],dp[l][r][1],dp[l][r][2],mx});
l--;
r++;
}
ans += mx;
}
for(int i = 2; i <= m; i++){
int l = n;
int r = i;
int mx = 0;
while(l >= 1 && l <= n && r >= 1 && r <= m){
dp[l][r][0] = max({dp[l+1][r-1][0],dp[l+1][r-1][1],dp[l+1][r-1][2]});
if(rem[l][r] == 'R'){
if(rem[l+1][r] == 'G' && rem[l+2][r] == 'W'){
dp[l][r][1] = dp[l+1][r-1][1];
if(r > 2) dp[l][r][1] = max({dp[l][r][1],dp[l+2][r-2][0],dp[l+2][r-2][1]});
if(r > 3) dp[l][r][1] = max({dp[l][r][1],dp[l+3][r-3][0],dp[l+3][r-3][1],dp[l+3][r-3][2]});
dp[l][r][1]++;
}
if(rem[l][r+1] == 'G' && rem[l][r+2] == 'W') dp[l][r][2] = max({dp[l+1][r-1][0],dp[l+1][r-1][1],dp[l+1][r-1][2]})+1;
}
mx = max({dp[l][r][0],dp[l][r][1],dp[l][r][2],mx});
l--;
r++;
}
ans += mx;
}
cout << ans;
}
//
// +.::=. .*: -.
// -- :. = -:--
// .= .. .-=++*+++=:. = :
// .= ....:=%@@@@@*: . :.
// .-+=..: :. .+##%##+. .: .+:
// :*@**%* .. :. ::..:.:. --:
// .--. +@@@@@%: .==: .###@*
// :-- -: -:@@@@# - =@@@@#. .= : +
// .: -=--==: == +- :*%*++= .:#
// -. .:. . +. -*. =@@. .-. .=
// +=.. .. -- .* .#. +@# - :==*=
// .=.+=:::: =. =- ##@+ :--+.#@%++%*
// .++@@: = + .%%%%@@@@@@@@@@@@@@%. :-@#-: -@.
// :@@@@= .+ .= *# .#@.=- =@::-:@:
// :-@@%. -- -- :@*. .%# +. - ** :=%. .*@#
// :-. .-*-. -: +. %-=::@# .* : - :%- +%.+@+@@
// .- :. **: +: = # : =* =@# -= # #@@@:-@ :*@@. %@
// -=: :: .* .= + # =..@ .*. +. *. *#=.+%@*-%* %@
// :=. :.. .: +. -= .+ # -- #. =- .+ +: =@+ .+-++ @%
// ++-=. * -- := # :- +- :* =:+: -@# :@#*%@@@%@+
// *. -- -- := # .= #@#=. +- :=+: :%@-#@@@#@+:@@#
// + +. -- := # .= := .+. +*. *@@+=@-=@*-.#@.
// = + := .+ # = .= .#.-@. -+ .%# -@@= @#
// .= .= .+ + *. = .+.. :*@ == =@. -#@#: @%
// .= .= * + =: .=.**: =--: # * *- %* =*=@+#@:
// .= := # =. .+ . .= --.#@@@@@#@@@: * -= #..@= **:@@@:
// + .= +: -- + # := +@%:@#: -:%= === #..* .#@@%@+.@@+
// * .= .* .= -:-= :- #= ++ =- =@. *: .* -*: : . .@@%
// * + * +. :- # -- # *: .@@ %- + =- +-.- :. .@@@.
// -: =: := .* +.-- =:-- .*.:.: # .= + *+ - :@%@=
// + * *:+. == .+ +. +.# .=-:=- -- -- =+: = -@#%*
// + -= *== *. -=-- :+-= ::: =: + %:. = %@+##
// .= +: +*- + +:+. +:*. .+ +: #.:. - .+ -@@=#%
// -. =. :=#- := =:* .-==#+- +: =- +:-..- :%* =@@:*%
// .- +. --+= .**%+-:. -* +-:*:.:. =@@* :-@@ *%
// -. += -+== -*#- =- .. .%@#@=.--@* *%
// =. .+: :+-*-=+: +%+*@@%%@-= +@- *#
// -::= :**=: :@@@@@@%@@- #@ #*
// -: +: - .@@#%@@%@@: :@# .#+
// :- :#= -- :@@@#@-=@#. =@- .%=
// =:.@@%= =# .+.=. +@@@@* -*: #% :@:
// .+ *@@@@@@@@* :@@*@@@* .@+ -@.
// .+=%@*%@@@@@#: =@@@%:.: +@: +%
// .=%@%#@@@@##@*: =%@@@#: @# ##
// :#@%@@@@#@@@@+ :*. @: =@- .@+
// .+@%#%@@:=-.. .=: %*==+. @% -@-
// =. =: :-:.:: .-- .= -: =@- -
// .- :-. :: .- =-:
// .=+-.=-.*- = -..+*: .-:.- = .+*# ....
// =. -= -: .. -. +. -. +. -+ -*=: +.
// .- +- * -.* #+ .+ =. :=
// :- --=*: -+ *= -# - -##+-.. .:+#: +.
// :- = --=:==+*. =: .: .= =**= = .+
// .= + =-- :- .=. -- .- =
// = .- --: .-+*@%*# +. + :-
// + +- -:- :*@@@@@@*@#*@@%*=: =: - -.
// .* - ::+ =@@@@#-.-@@%%@@+=%@@@%= -:: = :-
// .+ :. +-. #@@@= +@@@-#@@%. +@@@+ .:= .- +:
// .--. -. :=- :@@+ :@@@@# =@@@# -%@# -= :: :-+-
// * - + --. +@@#=%@@@@@. :@@@@% :%@ := =. -=+
// .-**- -. -- .%@@@@+%@+ @@+%@@*-+@@@. :=. - :+*-
// :===-==. .-= *@% *@= +%%##=. :=: :. .::-==-.
// .::-=+=+=-:. #%: -#: .-*#+===-:.
// ..::---====---::.
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |