fork download
  1. #include <bits/stdc++.h>
  2. #define fu(i,a,b) for(int i=a; i<=b; i++)
  3. #define fd(i,a,b) for(int i=a; i>=b; i--)
  4. #define X first
  5. #define Y second
  6. #define mtp make_tuple
  7. #define pro "huda"
  8. using namespace std;
  9.  
  10. typedef long long ll;
  11. typedef double db;
  12. typedef long double ldb;
  13. typedef pair<int,int> pii;
  14. typedef pair<string,int> si;
  15. const int maxN = 105;
  16. const long long oo = ll(1e17)+7;
  17.  
  18. template <typename T> inline void read(T &x)
  19. {
  20. x=0;
  21. char c;
  22. while (!isdigit(c=getchar()));
  23. do x=x*10+c-'0';
  24. while (isdigit(c=getchar()));
  25. }
  26.  
  27. template <typename T> inline void write(T x)
  28. {
  29. if (x>9) write(x/10);
  30. putchar(x%10+48);
  31. }
  32.  
  33. int n;
  34. pair<string,int> s[2*maxN];
  35. string suf[maxN],pre[maxN],rs[2*maxN];
  36.  
  37. bool cmp(si a, si b)
  38. {
  39. return (a.X.length()>=b.X.length());
  40. }
  41.  
  42. void suybien()
  43. {
  44. suf[n-1]=s[2].X;
  45. pre[n-1]=s[1].X;
  46. rs[s[2].Y]="S";
  47. rs[s[1].Y]="P";
  48. for(int i=3; i<=2*n-2; i+=2)
  49. {
  50. bool kt1=1,kt2=1;
  51. int l=s[i].X.length();
  52. ///bug(s[i],l,suf[l+1]);
  53. for(int j=0; j<=l-1; j++)
  54. if (s[i].X[j]!=suf[l+1][j+1])
  55. {
  56. kt1=0;
  57. break;
  58. }
  59. for(int j=0; j<=l-1; j++)
  60. if (s[i+1].X[j]!=pre[l+1][j])
  61. {
  62. kt2=0;
  63. break;
  64. }
  65. if ((kt1&&kt2))
  66. {
  67. suf[l]=s[i].X;
  68. pre[l]=s[i+1].X;
  69. rs[s[i].Y]="S";
  70. rs[s[i+1].Y]="P";
  71. } else
  72. {
  73. suf[l]=s[i+1].X;
  74. pre[l]=s[i].X;
  75. rs[s[i+1].Y]="S";
  76. rs[s[i].Y]="P";
  77. }
  78. }
  79. fu(i,1,2*n-2) cout << rs[i];
  80. }
  81.  
  82. int main()
  83. {
  84. ios_base::sync_with_stdio(0);
  85. cin.tie(0);
  86. cout.tie(0);
  87. #ifndef ONLINE_JUDGE
  88. freopen(pro".inp","r",stdin);
  89. freopen(pro".out","w",stdout);
  90. #endif
  91. cin >> n;
  92. fu(i,1,2*n-2)
  93. {
  94. string _s;
  95. cin >> _s;
  96. s[i]={_s,i};
  97. }
  98. sort(s+1,s+2*n-1,&cmp);
  99. suf[n-1]=s[1].X;
  100. pre[n-1]=s[2].X;
  101. rs[s[1].Y]="S";
  102. rs[s[2].Y]="P";
  103. ///bug1D(s,1,2*n-2);
  104. for(int i=3; i<=2*n-2; i+=2)
  105. {
  106. bool kt1=1,kt2=1,kt3=1,kt4=1;
  107. int l=s[i].X.length();
  108. ///bug(s[i],l,suf[l+1]);
  109. for(int j=0; j<=l-1; j++)
  110. if (s[i].X[j]!=suf[l+1][j+1])
  111. {
  112. kt1=0;
  113. break;
  114. }
  115. for(int j=0; j<=l-1; j++)
  116. if (s[i+1].X[j]!=pre[l+1][j])
  117. {
  118. kt2=0;
  119. break;
  120. }
  121. ///
  122. for(int j=0; j<=l-1; j++)
  123. if (s[i+1].X[j]!=suf[l+1][j+1])
  124. {
  125. kt3=0;
  126. break;
  127. }
  128. for(int j=0; j<=l-1; j++)
  129. if (s[i].X[j]!=pre[l+1][j])
  130. {
  131. kt4=0;
  132. break;
  133. }
  134. if ((kt1&&kt2))
  135. {
  136. suf[l]=s[i].X;
  137. pre[l]=s[i+1].X;
  138. rs[s[i].Y]="S";
  139. rs[s[i+1].Y]="P";
  140. } else
  141. {
  142. if (kt3&&kt4)
  143. {
  144. suf[l]=s[i+1].X;
  145. pre[l]=s[i].X;
  146. rs[s[i+1].Y]="S";
  147. rs[s[i].Y]="P";
  148. } else
  149. {
  150. suybien();
  151. exit(0);
  152. }
  153. }
  154. }
  155. fu(i,1,2*n-2) cout << rs[i];
  156. }
Success #stdin #stdout 0s 15400KB
std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