제출 #458143

#제출 시각아이디문제언어결과실행 시간메모리
458143JovanBMiners (IOI07_miners)C++17
100 / 100
251 ms604 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int dp[4][4][4][4]; int dpp[4][4][4][4]; int main(){ ios_base::sync_with_stdio(false); cout.precision(10); cout<<fixed; int n; cin >> n; string s; cin >> s; for(int a=0; a<=3; a++){ for(int b=0; b<=3; b++){ for(int c=0; c<=3; c++){ for(int d=0; d<=3; d++){ dpp[a][b][c][d] = -100000000; } } } } dpp[0][0][0][0] = 0; for(int i=1; i<=n; i++){ int x; if(s[i-1] == 'M') x = 1; else if(s[i-1] == 'F') x = 2; else x = 3; for(int a=0; a<=3; a++){ for(int b=0; b<=3; b++){ for(int c=0; c<=3; c++){ for(int d=0; d<=3; d++){ dp[a][b][c][d] = -100000000; } } } } for(int a=0; a<=3; a++){ for(int b=0; b<=3; b++){ for(int c=0; c<=3; c++){ for(int d=0; d<=3; d++){ bool bio[4]; for(int j=1; j<=3; j++) bio[j] = 0; bio[a] = 1; bio[b] = 1; bio[x] = 1; int sum = 0; for(int j=1; j<=3; j++){ sum += bio[j]; } dp[b][x][c][d] = max(dp[b][x][c][d], dpp[a][b][c][d] + sum); for(int j=1; j<=3; j++) bio[j] = 0; bio[c] = 1; bio[d] = 1; bio[x] = 1; sum = 0; for(int j=1; j<=3; j++){ sum += bio[j]; } dp[a][b][d][x] = max(dp[a][b][d][x], dpp[a][b][c][d] + sum); } } } } for(int a=0; a<=3; a++){ for(int b=0; b<=3; b++){ for(int c=0; c<=3; c++){ for(int d=0; d<=3; d++){ dpp[a][b][c][d] = dp[a][b][c][d]; } } } } } int mx = 0; for(int a=0; a<=3; a++){ for(int b=0; b<=3; b++){ for(int c=0; c<=3; c++){ for(int d=0; d<=3; d++){ mx = max(mx, dp[a][b][c][d]); } } } } cout << mx; 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...