Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.88 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:256000000")
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #define _CRT_SECURE_NO_DEPRECATE
  4. #include<iostream>
  5. #include<cstdio>
  6. #include<cstdlib>
  7. #include<string>
  8. #include<cstring>
  9. #include<algorithm>
  10. #include<cmath>
  11. #include <set>
  12. #include <queue>
  13. #include <map>
  14. #include <vector>
  15. #include <unordered_map>
  16. #include <assert.h>
  17.  
  18. using namespace std;
  19.  
  20. #define mp make_pair
  21. #define pub push_back
  22. #define con continue
  23. #define forn(i, n) for (int i = 0; i < int(n); ++i)
  24. #define fornr(i, n) for (int i = n - 1; i >= 0; --i)
  25. #define forab(i, a, b) for (int i = (a); i <= int(b); ++i)
  26. typedef long long ll;
  27. typedef pair <int, int> pii;
  28. typedef vector <int> vi;
  29. typedef vector < pii > vii;
  30. typedef vector < vector < int> > vvi;
  31. typedef vector < vector < pair < int, int > > > vvii;
  32.  
  33. const int ZEROS = (int)(1E+6 * 5 + 100);
  34. const int INF = (int)1E+9;
  35. const long double EPS = 1E-13;
  36.  
  37. pii A[30];
  38.  
  39. void solve() {
  40.     sort(A, A + 30);
  41.     reverse(A, A + 30);
  42.  
  43.     int k = 0;
  44.     int a1 = -1, a2 = -1, a3 = -1, a4 = -1;
  45.     int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
  46.     forn(i, 30) {
  47.         if (A[i].first > 0) {
  48.             x1 = A[i].first;
  49.             A[i].first--;
  50.             a1 = A[i].second;
  51.             forn(j, 30) {
  52.                 if (A[j].first > 0 && i != j) {
  53.                     x2 = A[j].first;
  54.                     A[j].first--;
  55.                     a2 = A[j].second;
  56.                     break;
  57.                 }
  58.             }
  59.             if (a2 != -1) {
  60.                 k++;
  61.                 break;
  62.             }
  63.         }
  64.     }
  65.     sort(A, A + 30);
  66.     forn(i, 30) { //4
  67.         if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2) {
  68.             x3 = A[i].first;
  69.             A[i].first = 0;
  70.             a3 = A[i].second;
  71.             forn(j, 30) {
  72.                 if (A[j].first > 0 && i != j && A[j].second != a1 && A[j].second != a2) {
  73.                     x4 = A[j].first;
  74.                     A[j].first = 0;
  75.                     a4 = A[j].second;
  76.                     break;
  77.                 }
  78.             }
  79.             if (a4 != -1) {
  80.                 k++;
  81.                 break;
  82.             }
  83.             else
  84.             {
  85.                 a3 = -1;
  86.                 A[i].first = x3;
  87.             }
  88.         }
  89.     }
  90.     bool u = false;
  91.     forn(i, 30) {
  92.         if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2
  93.             && A[i].second != a3 && A[i].second != a4) {
  94.             u = true;
  95.             break;
  96.         }
  97.     }
  98.     if (k == 0 || (a1 != -1 && a2 != -1 && a3 != -1 && a4 != -1 && u)) {
  99.         cout << "No";
  100.         return;
  101.     }
  102.     if (k < 2) {
  103.         A[a3].first = x3; A[a4].first = x4;
  104.         a3 = -1; a4 = -1;
  105.         k = 1;
  106.         forn(i, 30) { //3
  107.             if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2) {
  108.                 x3 = A[i].first;
  109.                 A[i].first = 0;
  110.                 a3 = A[i].second;
  111.                 forn(j, 30) {
  112.                     if (A[j].first > 0 && i != j) {
  113.                         x4 = A[j].first;
  114.                         A[j].first = 0;
  115.                         a4 = A[j].second;
  116.                         break;
  117.                     }
  118.                 }
  119.                 if (a4 != -1) {
  120.                     k++;
  121.                     break;
  122.                 }
  123.                 else
  124.                 {
  125.                     a3 = -1;
  126.                     A[i].first = x3;
  127.                 }
  128.             }
  129.         }
  130.         u = false;
  131.         forn(i, 30) {
  132.             if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2
  133.                 && A[i].second != a3 && A[i].second != a4) {
  134.                 u = true;
  135.                 break;
  136.             }
  137.         }
  138.         if (u || k < 2) {
  139.             A[a3].first = x3; A[a4].first = x4;
  140.             a3 = -1; a4 = -1;
  141.             k = 1;
  142.             forn(i, 30) { //2
  143.                 if (A[i].first > 0) {
  144.                     x3 = A[i].first;
  145.                     A[i].first = 0;
  146.                     a3 = A[i].second;
  147.                     forn(j, 30) {
  148.                         if (A[j].first > 0 && i != j) {
  149.                             x4 = A[j].first;
  150.                             A[j].first = 0;
  151.                             a4 = A[j].second;
  152.                             break;
  153.                         }
  154.                     }
  155.                     if (a4 != -1) {
  156.                         k++;
  157.                         break;
  158.                     }
  159.                     else
  160.                     {
  161.                         a3 = -1;
  162.                         A[i].first = x3;
  163.                     }
  164.                 }
  165.             }
  166.             u = false;
  167.             forn(i, 30) {
  168.                 if (A[i].first > 0 && A[i].second != a1 && A[i].second != a2
  169.                     && A[i].second != a3 && A[i].second != a4) {
  170.                     u = true;
  171.                     break;
  172.                 }
  173.             }
  174.             if (u || k < 2) {
  175.                 cout << "No";
  176.                 return;
  177.             }
  178.         }
  179.     }
  180.     cout << "Yes";
  181. }
  182.  
  183. int main() {
  184. #ifdef  _DEBUG
  185.     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
  186. #endif
  187.     ios_base::sync_with_stdio(0);
  188.     cin.tie(0);
  189.  
  190.     string s;
  191.     cin >> s;
  192.     set <char> S;
  193.     forn(i, (int)s.size()) {
  194.         A[s[i] - 'a'].first++;
  195.         A[s[i] - 'a'].second = s[i] - 'a';
  196.     }
  197.     solve();
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement