fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. using namespace std;
  10. #define all(v) (v.begin()), (v.end())
  11.  
  12. int main()
  13. {
  14. int t;
  15. cin >> t;
  16. while (t--)
  17. {
  18. int n;
  19. string str;
  20. cin >> n >> str;
  21.  
  22. int multiplier = 0;
  23.  
  24. for (int i = 0; i < n; i++)
  25. {
  26. char current = str[i];
  27. if (multiplier == 0)
  28. {
  29. multiplier = 1;
  30. }
  31. else
  32. {
  33. multiplier = 0;
  34. }
  35. for (int j = 0; j < n; j++)
  36. {
  37. if (str[j] == current)
  38. {
  39. str[j] = multiplier + '0';
  40. }
  41. }
  42. }
  43. for (int j = 0; j < n - 1; j++)
  44. {
  45. if (str[j] == str[j + 1])
  46. {
  47. cout << "NO" << endl;
  48. break;
  49. }
  50. if (j == n - 2)
  51. {
  52. cout << "YES" << endl;
  53. }
  54. }
  55. if (n == 1)
  56. {
  57. cout << "YES" << endl;
  58. }
  59. }
  60. }
Success #stdin #stdout 0s 5272KB
stdin
8
7
abacaba
2
aa
1
y
4
bkpt
6
ninfia
6
banana
10
codeforces
8
testcase
stdout
YES
NO
YES
YES
NO
YES
NO
NO