Dの範囲をリバースする。
class PermutationSignature { public: vector <int> reconstruct(string S) { vector<string> v; string s; s += S[0]; for (int i = 1; i < (int)S.size(); ++i) { if (s[0] == S[i]) s += S[i]; else { v.push_back(s); s = ""; s += S[i]; } } if (s.size()) v.push_back(s); vector <int> res; for (int i = 0; i <= (int)S.size(); ++i) { res.push_back(i + 1); } int idx = 0; for (int i = 0; i < (int)v.size(); ++i) { if (v[i][0] == 'D') { reverse(res.begin() + idx, res.begin() + idx + v[i].size() + 1); } idx += v[i].size(); } return res; } };