제출 #1022626

#제출 시각아이디문제언어결과실행 시간메모리
1022626ttamxMiners (IOI07_miners)C++17
84 / 100
1607 ms100912 KiB
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; const int INF=INT_MAX/2; int n; int dp[N][4][4][4][4]; string s; int ans; int calc(int a,int b,int c){ set<int> s{a,b,c}; s.erase(0); return s.size(); } void chmax(int &x,int v){ if(v>x)x=v; } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n; cin >> s; for(int i=0;i<=n;i++){ for(int x=0;x<4;x++){ for(int y=0;y<4;y++){ for(int z=0;z<4;z++){ for(int w=0;w<4;w++){ dp[i][x][y][z][w]=-INF; } } } } } dp[0][0][0][0][0]=0; for(int i=0;i<n;i++){ int v=s[i]=='M'?1:s[i]=='F'?2:3; for(int x=0;x<4;x++){ for(int y=0;y<4;y++){ for(int z=0;z<4;z++){ for(int w=0;w<4;w++){ chmax(dp[i+1][x][y][w][v],dp[i][x][y][z][w]+calc(z,w,v)); chmax(dp[i+1][y][v][z][w],dp[i][x][y][z][w]+calc(x,y,v)); } } } } } for(int x=0;x<4;x++){ for(int y=0;y<4;y++){ for(int z=0;z<4;z++){ for(int w=0;w<4;w++){ chmax(ans,dp[n][x][y][z][w]); } } } } 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...