Advertisement
El_GEMMY

contest

Apr 28th, 2022
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.49 KB | None | 0 0
  1. // Those who cannot remember the past are
  2. // condemned to repeat it (use DP -_-)
  3. // - George Santayana
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8.  
  9. using namespace std;
  10. using namespace __gnu_pbds;
  11.  
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define ll long long
  15. #define ull unsigned long long
  16. #define MOD 1000000007
  17. #define PI 3.14159265
  18. #define ceil(a, b) (((a) / (b)) + ((a) % (b) ? 1 : 0))
  19. #define imin INT_MIN
  20. #define imax INT_MAX
  21. #define llmax LLONG_MAX
  22. #define llmin LLONG_MIN
  23. #define inf 2000000000
  24. #define nl '\n'
  25. #define ppcnt __builtin_popcount
  26. #define ppcntll __builtin_popcountll
  27. #define clz __builtin_clz
  28. #define clzll __builtin_clzll
  29. #define ctz __builtin_ctz
  30. #define ctzll __builtin_ctzll
  31. #define modulo(a, b, mod) ((((a) % (mod)) + ((b) % (mod))) % (mod))
  32. #define cnte(v, x) count(all(v), (x))
  33. #define mine(v) min_element(all(v))
  34. #define maxe(v) max_element(all(v))
  35. #define updmin(a, b) a = min(a, b)
  36. #define updmax(a, b) a = max(a, b)
  37. #define finmod(x, m) x = ((x) % (m) + (m)) % m
  38. #define debug(x) cout << "x: " << (x) << nl;
  39. #define debug2(x, y) cout << "x: " << (x) << " y: " << y << nl;
  40. #define ordered_set tree<pair<int, int>, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>
  41. #define ordered_map tree<int, int, less<>, rb_tree_tag, tree_order_statistics_node_update>
  42.  
  43. //vector<int> dx = {0, 0, 1, -1, 1, 1, -1, -1}, dy = {1, -1, 0, 0, 1, -1, 1, -1};
  44. //vector<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};
  45.  
  46. template<typename T = int> istream& operator>>(istream& in, vector<pair<int, int>>& v){
  47.     for (auto& [x, y] : v) in >> x >> y;
  48.     return in;
  49. }
  50.  
  51. template<typename T = int> istream& operator>>(istream& in, vector<T>& v){
  52.     for (T& i : v) in >> i;
  53.     return in;
  54. }
  55.  
  56. template<typename T = int> ostream& operator<<(ostream& out, const vector<T>& v){
  57.     for (const T& x : v)
  58.         out << x << ' ';
  59.     return out;
  60. }
  61.  
  62. template<typename T = pair<int, int>> ostream& operator << (ostream& out, const vector<pair<int, int>>& v){
  63.     for(auto& [x, y] : v){
  64.         out << x << ' ' << y << nl;
  65.     }
  66.     return out;
  67. }
  68.  
  69. void Start_Crushing() {
  70.     ios_base::sync_with_stdio(false);
  71.     cin.tie(nullptr);
  72.     cout.tie(nullptr);
  73. #ifndef ONLINE_JUDGE
  74.     freopen("input.txt", "r", stdin);
  75.     freopen("output.txt", "w", stdout);
  76. #endif
  77. }
  78.  
  79. struct item{
  80.     int i, j, base, k;
  81.  
  82.     item(){
  83.         i = j = base = k = 0;
  84.     }
  85.  
  86.     item(int i, int j, int base, int k){
  87.         this -> i = i;
  88.         this -> j = j;
  89.         this -> base = base;
  90.         this -> k = k;
  91.     }
  92. };
  93.  
  94. void solve(){
  95.     string s; cin >> s;
  96.  
  97.     vector<int> freq(6);
  98.     for(auto& i : s){
  99.         freq[i - 'A' + 1]++;
  100.     }
  101.  
  102.  
  103.  
  104.     if(not freq[1]){
  105.         return void(cout << "NO");
  106.     }
  107.     freq[1]--;
  108.     vector<int> cpy(freq);
  109.     bool first = true, second = true;
  110.  
  111.     for(int i = 2; i <= 5; i++){
  112.         bool ok = false;
  113.         for(int j = 1; j < i; j++){
  114.             for(int k = 1; k < i; k++){
  115.                 if(j + k == i and freq[j] and freq[k]){
  116.                     if(j == k and freq[j] < 2)
  117.                         break;
  118.                     freq[j]--, freq[k]--;
  119.                     ok = true;
  120.                 }
  121.             }
  122.         }
  123.         if(ok){
  124.             continue;
  125.         }
  126.         if(not freq[i]) {
  127.             first = false;
  128.             break;
  129.         }
  130.         freq[i]--;
  131.     }
  132.  
  133.     freq = cpy;
  134.     for(int i = 2; i <= 5; i++){
  135.         bool ok = false;
  136.         if(freq[i]){
  137.             freq[i]--;
  138.             ok = true;
  139.         }
  140.         if(ok){
  141.             continue;
  142.         }
  143.  
  144.         for(int j = 1; j < i; j++){
  145.             for(int k = 1; k < i; k++){
  146.                 if(j + k == i and freq[j] and freq[k]){
  147.                     if(j == k and freq[j] < 2)
  148.                         break;
  149.                     freq[j]--, freq[k]--;
  150.                     ok = true;
  151.                 }
  152.             }
  153.         }
  154.         if(not ok){
  155.             second = false;
  156.             break;
  157.         }
  158.     }
  159.     cout << (first or second ? "YES" : "NO");
  160. }
  161.  
  162. int main(){
  163.     Start_Crushing();
  164.  
  165.     int t = 1;
  166.     /*Multiple test cases?*/ cin >> t;
  167.     while (t--) {
  168.         solve();
  169.         if(!t)
  170.             break;
  171.         cout << nl;
  172.     }
  173.  
  174. //    for(int tc = 1; tc <= t; tc++){
  175. //        cout << "Case #" << tc << ": ";
  176. //        solve();
  177. //        if(tc != t)
  178. //            cout << nl;
  179. //    }
  180.  
  181.     return 0;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement