제출 #992687

#제출 시각아이디문제언어결과실행 시간메모리
992687ezzzayMiners (IOI07_miners)C++14
100 / 100
185 ms100836 KiB
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back const int N=1e5+5; int dp[4][4][4][4][N]; int mp[500]; int fun(int x,int y, int k){ if(x==0 and y==0)return 1; if(x==0){ if(y==k)return 1; return 2; } if(x==y and x==k)return 1; if(x!=y and y!=k and k!=x)return 3; return 2; } signed main(){ mp['M'-'A']=1; mp['F'-'A']=2; mp['B'-'A']=3; int n; string s; cin>>n>>s; int h=mp[s[0]-'A']; for(int i=0;i<n;i++){ for(int x1=0;x1<4;x1++){ for(int y1=0;y1<4;y1++){ for(int x2=0;x2<4;x2++){ for(int y2=0;y2<4;y2++){ dp[x1][y1][x2][y2][i]=-1e9; } } } } } dp[0][h][0][0][0]=1; dp[0][0][0][h][0]=1; for(int i=1;i<n;i++){ int k=mp[s[i]-'A']; for(int x1=0;x1<4;x1++){ for(int y1=0;y1<4;y1++){ for(int x2=0;x2<4;x2++){ for(int y2=0;y2<4;y2++){ int h=fun(x1,y1,k); dp[y1][k][x2][y2][i]=max(dp[y1][k][x2][y2][i],dp[x1][y1][x2][y2][i-1]+h); h=fun(x2,y2,k); dp[x1][y1][y2][k][i]=max(dp[x1][y1][y2][k][i],dp[x1][y1][x2][y2][i-1]+h); } } } } } int mx=0; for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ for(int k=0;k<4;k++){ for(int l=0;l<4;l++){ mx=max(mx,dp[i][j][k][l][n-1]); } } } } cout<<mx; }
#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...