제출 #872866

#제출 시각아이디문제언어결과실행 시간메모리
872866josanneo22Miners (IOI07_miners)C++17
84 / 100
1546 ms1372 KiB
/* Problem: IOI 2007 Miners When: 2023-11-13 21:27:07 Author: JN */ #include<bits/stdc++.h> using namespace std; using i64 = long long; using pii = pair<int, int>; #define L(i,j,k) for(int i=(j);i<=(k);++i) #define R(i,j,k) for(int i=(j);i>=(k);--i) #define all(x) x.begin(), x.end() int dp[500][4][4][4][4]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin>>n; string s; cin>>s; vector<int> a(n+1); L(i,0,n-1){ if(s[i]=='M') a[i]=1; if(s[i]=='B') a[i]=2; if(s[i]=='F') a[i]=3; } memset(dp,-1,sizeof(dp)); dp[0][0][0][0][0]=0; auto profit=[&](int x,int y,int z){ set<int> s; s.insert(x); s.insert(y); s.insert(z); int cnt=s.size(); if(*s.begin()==0) cnt--; return cnt; }; L(i,0,n-1){ int nw=i&1,nx=nw^1; L(a1,0,3) L(a2,0,3) L(b1,0,3) L(b2,0,3){ if(dp[nw][a1][a2][b1][b2]==-1) continue; dp[nx][a2][a[i]][b1][b2]=max(dp[nx][a2][a[i]][b1][b2], dp[nw][a1][a2][b1][b2]+profit(a1,a2,a[i])); dp[nx][a1][a2][b2][a[i]]=max(dp[nx][a1][a2][b2][a[i]], dp[nw][a1][a2][b1][b2]+profit(b1,b2,a[i])); // cout<<a1<<' '<<a2<<' '<<b1<<' '<<b2<<' '; // cout<<profit(a1,a2,a[i])<<' '; // cout<<profit(b1,b2,a[i])<<'\n'; } } int ans=0,nw=n&1; L(a1,0,3) L(a2,0,3) L(b1,0,3) L(b2,0,3){ if(ans<dp[nw][a1][a2][b1][b2]){ ans=dp[nw][a1][a2][b1][b2]; } } cout<<ans<<'\n'; }
#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...