Submission #902503

#TimeUsernameProblemLanguageResultExecution timeMemory
90250312345678Miners (IOI07_miners)C++17
100 / 100
182 ms101156 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e5+5; int n, dp[nx][4][4][4][4], v[nx], ans; string s; int val(int a, int b, int c) { if (a==3&&b==3) return 1; if (a==3) return 1+(b!=c); if (a==b&&b==c) return 1; if (a==b||b==c||a==c) return 2; return 3; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>s; if (n==1) return 1; for (int i=0; i<n; i++) v[i+1]=s[i]=='B'?0:(s[i]=='F'?1:2); for (int i=0; i<=n; i++) for (int j=0; j<4; j++) for (int k=0; k<4; k++) for (int x=0; x<4; x++) for (int y=0; y<4; y++) dp[i][j][k][x][y]=-1e9; dp[0][3][3][3][3]=0; for (int i=1; i<=n; i++) { for (int l1=0; l1<4; l1++) { for (int l2=0; l2<4; l2++) { for (int r1=0; r1<4; r1++) { for (int r2=0; r2<4; r2++) { dp[i][l1][l2][r2][v[i]]=max(dp[i][l1][l2][r2][v[i]], dp[i-1][l1][l2][r1][r2]+val(r1, r2, v[i])); dp[i][l2][v[i]][r1][r2]=max(dp[i][l2][v[i]][r1][r2], dp[i-1][l1][l2][r1][r2]+val(l1, l2, v[i])); ans=max({ans, dp[i][l1][l2][r2][v[i]], dp[i][l2][v[i]][r1][r2]}); } } } } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...