Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <vector>
- #include <iomanip>
- #include <algorithm>
- //https://codeforces.com/group/auuF4i8Rom/contest/238530/problem/D
- using namespace std;
- #define forn(i, n) for (int i = 0; i < (int) n; ++i)
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- #endif // _DEBUG
- int n;
- cin >> n;
- vector<string> a(2 * n - 2);
- string s1, s2, s3, s4;
- s1 = s2 = s3 = s4 = "";
- forn(i, 2 * n - 2)
- {
- cin >> a[i];
- if (a[i].length() == 1)
- if (s1.length() == 1)
- s2 = a[i];
- else
- s1 = a[i];
- if (a[i].length() == n - 1)
- if (s3.length() == n - 1)
- s4 = a[i];
- else
- s3 = a[i];
- }
- vector<string> t;
- if (s1 + s3 == s4 + s2)
- t.push_back(s1 + s3);
- if (s1 + s4 == s3 + s2)
- t.push_back(s1 + s4);
- if (s2 + s3 == s4 + s1)
- t.push_back(s2 + s3);
- if (s2 + s4 == s3 + s1)
- t.push_back(s2 + s4);
- forn(k, t.size())
- {
- string s = t[k];
- string rs = s;
- rs.reserve();
- vector<bool> used(n, 0);
- vector<bool> usedIDX(2 * n - 2, 0);
- vector<char> ans(2 * n - 2);
- int use = 0;
- bool fl = true;
- forn(i, 2 * n - 2)
- {
- string cur = a[i];
- if (used[cur.length()])
- continue;
- if (s.find(cur) == string::npos)
- {
- fl = false;
- break;
- }
- used[cur.length()] = 1;
- usedIDX[i] = 1;
- use++;
- ans[i] = 'P';
- }
- forn(i, n)
- used[i] = 0;
- if (use != n - 1)
- continue;
- use = 0;
- forn(i, 2 * n - 2)
- {
- string cur = a[i];
- if (usedIDX[i])continue;
- if (used[i])continue;
- if (rs.find(cur) == string::npos)
- {
- fl = false;
- break;
- }
- used[cur.length()] = 1;
- use++;
- ans[i] = 'S';
- }
- if (use != n - 1)
- continue;
- forn(i, 2 * n - 2)
- cout << ans[i];
- return 0;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement