Advertisement
Guest User

JAPC1004 Setter Solution

a guest
May 2nd, 2021
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define LL long long int
  5. const LL MOD=1e9+7;
  6.  
  7. // When something is important enough, you do it even if the odds are not in your favor.
  8.  
  9. int main(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(NULL);
  12. #ifdef somujena
  13. freopen("/home/somujena/competitive/input.txt", "r", stdin);
  14. freopen("/home/somujena/competitive/output.txt", "w", stdout);
  15. #endif
  16. // code goes here
  17. LL test=1; cin>>test;
  18. while(test--){
  19. LL n,i,j;cin>>n;
  20. string s;cin>>s;
  21. LL r,g,b;cin>>r>>g>>b;
  22. LL dp[n][3];
  23. // 0 means Red, 1 means Green, 2 means Blue
  24. for( i=0;i<n;i++){
  25. // paint in Red
  26. if(s[i]=='R'){
  27. dp[i][0]=0;
  28. }
  29. else{
  30. dp[i][0]=r;
  31. }
  32. if(i>0) dp[i][0]+=min(dp[i-1][1],dp[i-1][2]);
  33.  
  34. // paint in Green
  35. if(s[i]=='G'){
  36. dp[i][1]=0;
  37. }
  38. else{
  39. dp[i][1]=g;
  40. }
  41. if(i>0) dp[i][1]+=min(dp[i-1][0],dp[i-1][2]);
  42.  
  43. // paint in Blue
  44. if(s[i]=='B'){
  45. dp[i][2]=0;
  46. }
  47. else{
  48. dp[i][2]=b;
  49. }
  50. if(i>0) dp[i][2]+=min(dp[i-1][0],dp[i-1][1]);
  51.  
  52. }
  53. cout<<min({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
  54. // if(dp[n-1][1]==5) cout<<1;
  55.  
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement