Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
//#include
using namespace std; const int INF = 2e9; typedef long long ll; int n; string s; int dp[2][4][4][4][4]; int main() { ios_base::sync_with_stdio(false); cin >> n >> s; for(int at = 0; at < 2; at++) { for(int l1 = 0; l1 <= 3; l1++) { for(int l2 = 0; l2 <= 3; l2++) { for(int r1 = 0; r1 <= 3; r1++) { for(int r2 = 0; r2 <= 3; r2++) { dp[at][l1][l2][r1][r2] = -INF; } } } } } dp[0][0][0][0][0] = 0; for(int at = 0; at < n; at++) { for(int l1 = 0; l1 <= 3; l1++) { for(int l2 = 0; l2 <= 3; l2++) { for(int r1 = 0; r1 <= 3; r1++) { for(int r2 = 0; r2 <= 3; r2++) { int now = at % 2; int next = 1 - now; int color = 0; if(s[at] == 'G') { color = 1; } else if(s[at] == 'R') { color = 2; } else { color = 3; } vector
visited(4, false); visited[l1] = true; visited[l2] = true; visited[color] = true; int score = visited[1] + visited[2] + visited[3]; dp[next][color][l1][r1][r2] = max(dp[now][l1][l2][r1][r2] + score, dp[next][color][l1][r1][r2]); visited[1] = false; visited[2] = false; visited[3] = false; visited[r1] = true; visited[r2] = true; visited[color] = true; score = visited[1] + visited[2] + visited[3]; dp[next][l1][l2][color][r1] = max(dp[next][l1][l2][color][r1], dp[now][l1][l2][r1][r2] + score); } } } } } int res = 0; for(int at = 0; at < 2; at++) { for(int l1 = 0; l1 <= 3; l1++) { for(int l2 = 0; l2 <= 3; l2++) { for(int r1 = 0; r1 <= 3; r1++) { for(int r2 = 0; r2 <= 3; r2++) { res = max(res, dp[at][l1][l2][r1][r2]); } } } } } cout << res << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)