제출 #1011402

#제출 시각아이디문제언어결과실행 시간메모리
1011402kaopjMiners (IOI07_miners)C++17
100 / 100
77 ms101212 KiB
#pragma GCC optimize("O3","unroll-loops") #include <iostream> #include <string.h> #define lgm cin.tie(0)->sync_with_stdio(0); using namespace std; signed main() { lgm; int n; cin >> n; char x[n+1]; int c[n]; cin >> x; for (int i=0;i<n;i++) { if (x[i] == 'M') { c[i]=0; } else if (x[i] == 'B') { c[i]=1; } else { c[i]=2; } } int dp[n+1][4][4][4][4]; memset(dp,0,sizeof dp); int mx=0; for (int i=1;i<=n;i++) { for (int p1=0;p1<3;p1++) { for (int p2=0;p2<3;p2++) { for (int q1=0;q1<3;q1++) { for (int q2=0;q2<3;q2++) { int cnt1,cnt2; if (p1 == p2 && c[i-1] == p1) { cnt1=1; } else if (p1 ^ p2 && c[i-1] ^ p1 && c[i-1] ^ p2) { cnt1=3; } else { cnt1=2; } if (q1 == q2 && c[i-1] == q1) { cnt2=1; } else if (q1 ^ q2 && c[i-1] ^ q1 && c[i-1] ^ q2) { cnt2=3; } else { cnt2=2; } dp[i][p2][c[i-1]][q1][q2]=max(dp[i][p2][c[i-1]][q1][q2],dp[i-1][p1][p2][q1][q2]+cnt1); mx=max(mx,dp[i][p2][c[i-1]][q1][q2]); dp[i][p1][p2][q2][c[i-1]]=max(dp[i][p1][p2][q2][c[i-1]],dp[i-1][p1][p2][q1][q2]+cnt2); mx=max(mx,dp[i][p1][p2][q2][c[i-1]]); } } } } } cout << mx-6; return 0; }
#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...