Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4. int tA = 0, tC = 0, tB = 0, tK1 = 0, tK2 = 0, tK3 = 0, tK4 = 0;
  5.  
  6. queue<int> q;
  7. void K4(char ch){
  8.     tC = tK4 + 4;
  9. }
  10. void K3(char ch){
  11.     if (ch == 'B'){
  12.         tB = tK3 + 2;
  13.     }
  14.     else{
  15.         tC = tK3 + 4;
  16.     }
  17. }
  18. void K2(char ch){
  19.     tB = tK2 + 2;
  20. }
  21. void K1(char ch){
  22.     if (ch == 'B'){
  23.         q.push(6);
  24.     }
  25.     else{
  26.         q.push(12);
  27.     }
  28.     int tmp = q.front();
  29.     if (tK3 <= tK1){
  30.         if (tmp == 6){
  31.             tK3 = tK1 + 4;
  32.             K3('B');
  33.         }
  34.         else{
  35.             tK3 = tK1 + 8;
  36.             K3('C');
  37.         }
  38.         q.pop();
  39.     }
  40.     else if (tmp == 6 && tK2 <= tK1){
  41.         tK2 = tK1 + 6;
  42.         K2('B');
  43.         q.pop();
  44.     }
  45.     else if (tmp == 12 && tK4 <= tK1){
  46.         tK4 = tK1 + 12;
  47.         K4('C');
  48.         q.pop();
  49.     }
  50.     else {
  51.         if (tmp == 6){
  52.             tK1 = min(tK3, tK2);
  53.         }
  54.         else tK1 = min(tK3, tK4);
  55.     }
  56. }
  57. void A(char ch){
  58.     if (ch == 'B'){
  59.         tK1 += 1;
  60.     }
  61.     else tK1 += 2;
  62.     K1(ch);
  63. }
  64. int main(){
  65.     for (int i = 0; i < 16; ++i){
  66.         char ch;
  67.         cin >> ch;
  68.         A(ch);
  69.     }
  70.     while(!q.empty()){
  71.         int tmp = q.front();
  72.         if (tK3 <= tK1){
  73.             if (tmp == 6){
  74.                 tK3 = tK1 + 4;
  75.                 K3('B');
  76.             }
  77.             else{
  78.                 tK3 = tK1 + 8;
  79.                 K3('C');
  80.             }
  81.             q.pop();
  82.         }
  83.         else if (tmp == 6 && tK2 <= tK1){
  84.             tK2 = tK1 + 6;
  85.             K2('B');
  86.             q.pop();
  87.         }
  88.         else if (tmp == 12 && tK4 <= tK1){
  89.             tK4 = tK1 + 12;
  90.             K4('C');
  91.             q.pop();
  92.         }
  93.         else {
  94.             if (tmp == 6){
  95.                 tK1 = min(tK3, tK2);
  96.             }
  97.             else tK1 = min(tK3, tK4);
  98.         }
  99.     }
  100.     cout << max(tB, tC);
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement