Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define LL long long int
- const LL MOD=1e9+7;
- // When something is important enough, you do it even if the odds are not in your favor.
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- #ifdef somujena
- freopen("/home/somujena/competitive/input.txt", "r", stdin);
- freopen("/home/somujena/competitive/output.txt", "w", stdout);
- #endif
- // code goes here
- LL test=1; cin>>test;
- while(test--){
- LL n,i,j;cin>>n;
- string s;cin>>s;
- LL r,g,b;cin>>r>>g>>b;
- LL dp[n][3];
- // 0 means Red, 1 means Green, 2 means Blue
- for( i=0;i<n;i++){
- // paint in Red
- if(s[i]=='R'){
- dp[i][0]=0;
- }
- else{
- dp[i][0]=r;
- }
- if(i>0) dp[i][0]+=min(dp[i-1][1],dp[i-1][2]);
- // paint in Green
- if(s[i]=='G'){
- dp[i][1]=0;
- }
- else{
- dp[i][1]=g;
- }
- if(i>0) dp[i][1]+=min(dp[i-1][0],dp[i-1][2]);
- // paint in Blue
- if(s[i]=='B'){
- dp[i][2]=0;
- }
- else{
- dp[i][2]=b;
- }
- if(i>0) dp[i][2]+=min(dp[i-1][0],dp[i-1][1]);
- }
- cout<<min({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
- // if(dp[n-1][1]==5) cout<<1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement