Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. const int N = 2e3 + 3, MOD = 998244353;
  8. pair <string, int> a[N];
  9. char b[N];
  10.  
  11. bool cmp(pair <string, int> a, pair <string , int> b) {
  12. //string l = a.first,
  13. return a.first.size() < b.first.size();
  14. }
  15.  
  16. main()
  17. {
  18. ios_base::sync_with_stdio(0);
  19. cin.tie(0);
  20.  
  21. /* A
  22. int t;
  23. cin >> t;
  24. for (int j = 0; j < t; j++) {
  25. int n, k, k1;
  26. cin >> n >> k;
  27. k1 = k;
  28. char c = 'a';
  29. int i = 0;
  30. string s = "";
  31. for (i = 0; i < n; i++) {
  32. s+= c;
  33. c+= 1;
  34. if (i == k1 - 1) c = 'a', k1+= k ;
  35. }
  36. cout << s << "\n";
  37. }*/
  38. /* B
  39. int n, kol = 0;
  40. cin >> n;
  41. for (int i = 0; i < n; i++) {
  42. cin >> a[i];
  43. }
  44. sort(a, a + n);
  45. for (int i = 0; i < n; i+=2) {
  46. kol+= abs(a[i] - a[i + 1]);
  47. }
  48. cout << kol;*/
  49. int n;
  50. cin >> n;
  51. for (int i = 0; i < 2 * n - 2; i++) {
  52. cin >> a[i].first;
  53. a[i].second = i;
  54. }
  55. sort(a, a + n * 2 - 2, cmp);
  56. string kek = a[0].first, kek1 = a[1].first;
  57. b[a[0].second] = 'P';
  58. b[a[1].second] = 'S';
  59. int kol = 1, kol1 = 1;
  60. bool ok = true;
  61. for (int i = 2; i < 2 * n - 2; i+= 2) {
  62. string h = "", h1 = "", mem = a[i].first, mem1 = a[i + 1].first;
  63. for (int j = 0; j < kek.size(); j++) {
  64. h+= mem[j];
  65. }
  66. int l = kek1.size() - 1;
  67. for (int j = mem1.size() - 1; l >= 0; j--) {
  68. h1+= mem1[j];
  69. l--;
  70. }
  71. reverse(h1.begin(), h1.end());
  72. /*3
  73. a
  74. b
  75. Aa
  76. bB*/
  77. // cout << h << endl << h1 << endl << endl;
  78. if (h != kek || h1 != kek1 || kek == h) {
  79. if ((h != kek || h1 != kek1) ) {
  80. //cout << h << ' ' << kek << ' ' << kek1 << ' ' << h1 << endl << endl;
  81. ok = false;
  82. }
  83. b[a[i].second] = 'P';
  84. b[a[i + 1].second] = 'S';
  85. kek = a[i].first;
  86. kek1 = a[i + 1].first;
  87. }
  88. else {
  89. b[a[i + 1].second] = 'P';
  90. b[a[i].second] = 'S';
  91. kek = a[i + 1].first;
  92. kek1 = a[i].first;
  93. }
  94. //cout << a[i].second << ' ' << a[i +1].second << endl;
  95. }
  96. if (!ok) {
  97. for (int i = 0; i < 2 * n - 2; i++) {
  98. if (b[i] == 'S') cout << 'P';
  99. else cout << 'S';
  100. }
  101. return 0;
  102. }
  103. for (int i = 0; i < 2 * n - 2; i++) cout << b[i];
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement