Naxocist

Tom Pud Tod [Crack n Code]

May 15th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using pi = pair<int, int>;
  6. using tiii = tuple<int, int, int>;
  7.  
  8. const ll INF = 1e9 + 7;
  9.  
  10. void solve(){
  11.    
  12.     int n; cin >> n;
  13.  
  14.     stack<int> s;
  15.     int cnt = 0, r = 0;
  16.     while(n--){
  17.         int x; cin >> x;
  18.         r++;
  19.         if(s.size() && s.top() == x){
  20.             cnt++;
  21.             s.pop();
  22.             r-=2;
  23.         }else {
  24.             s.push(x);
  25.         }
  26.  
  27.         if(r >= 3){
  28.             int k = 3;
  29.             stack<int> t(s);
  30.             unordered_set<int> us;
  31.             while(k--) us.insert(t.top()) , t.pop();
  32.  
  33.             if(us.size() == 3) {
  34.                 cnt++;
  35.                 s = t;
  36.                 r -= 3;
  37.             }
  38.         }
  39.        
  40.     }
  41.  
  42.    
  43.     if(r){
  44.         cout << "No\n" << cnt << '\n' << r << '\n';
  45.     }else{
  46.         cout << "Yes\n" << cnt << '\n';
  47.     }
  48.     return ;
  49. }
  50.  
  51.  
  52. int main() {
  53.     ios_base::sync_with_stdio(false); cin.tie(nullptr);
  54.  
  55.     // freopen("input.in", "r", stdin);
  56.     int t; cin >> t;
  57.     while(t--) solve();
  58.  
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment