제출 #976845

#제출 시각아이디문제언어결과실행 시간메모리
976845vjudge1Miners (IOI07_miners)C++17
100 / 100
69 ms100956 KiB
#include<bits/stdc++.h> using namespace std; const int NN=1e5+1; // m 1 b 2 f 3 int gv(char c){ return (c=='M'? 1:c=='B'? 2:3); } int cal(int i,int j,int k){ int z=(i==0)+(j==0)+(k==0); if(z==0) { if(i!=j&&j!=k&&k!=i) return 3; else if(i==j&&j==k) return 1; else return 2; } else if(z==2) return 1; else{ if(j==0) swap(i,j); return (j!=k)+1; } } int arr[NN][4][4][4][4]; int n; string s; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); memset(arr,-1,sizeof(arr)); cin>>n>>s; arr[0][0][0][0][0]=0; for(int i=0;i<n;i++){ for(int i1=0;i1<=3;i1++){ for(int j1=0;j1<=3;j1++){ for(int i2=0;i2<=3;i2++){ for(int j2=0;j2<=3;j2++){ if(arr[i][i1][j1][i2][j2]==-1) continue; int t=gv(s[i]); arr[i+1][j1][t][i2][j2]=max(arr[i+1][j1][t][i2][j2],arr[i][i1][j1][i2][j2]+cal(i1,j1,t)); arr[i+1][i1][j1][j2][t]=max(arr[i+1][i1][j1][j2][t],arr[i][i1][j1][i2][j2]+cal(i2,j2,t)); } } } } } int mx=0; for(int i1=0;i1<=3;i1++){ for(int j1=0;j1<=3;j1++){ for(int i2=0;i2<=3;i2++){ for(int j2=0;j2<=3;j2++){ mx=max(mx,arr[n][i1][j1][i2][j2]); } } } } 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...