Submission #416366

#TimeUsernameProblemLanguageResultExecution timeMemory
416366model_codeRPS string (innopolis2021_final_C)C++17
16 / 100
3069 ms7244 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 5000 + 10; bool dp[MAXN][MAXN][3]; int a[MAXN]; map<char, int> cv = {{'r', 0}, {'s', 1}, {'p', 2}}; bool win[3][3]; bool win1[3][3]; string solve_stupid(int t, string s) { for (int j = 0; j < 3; ++j) { for (int k = 0; k <= 1; ++k) { win[j][(j + k) % 3] = 1; } } int n = s.size(); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { for (int k = 0; k < 3; ++k) { dp[i][j][k] = 0; } } } for (int i = 0; i < n; ++i) { a[i] = cv[s[i]]; dp[i][i][a[i]] = 1; } for (int l = n - 1; l >= 0; --l) { for (int r = l + 1; r < n; ++r) { for (int m = l; m < r; ++m) { for (int k = 0; k < 3; ++k) { for (int k1 = 0; k1 < 3; ++k1) { if (dp[l][m][k] && dp[m + 1][r][k1]) { if (win[k][k1]) { dp[l][r][k] = 1; } if (win[k1][k]) { dp[l][r][k1] = 1; } } } } } } } string ans; for (int i = 0; i < n; ++i) { bool left = 0; if (i == 0) { left = 1; } else { for (int k = 0; k < 3; ++k) { if (win[a[i]][k] && dp[0][i - 1][k]) { left = 1; } } } bool right = 0; if (i == n - 1) { right = 1; } else { for (int k = 0; k < 3; ++k) { if (win[a[i]][k] && dp[i + 1][n - 1][k]) { right = 1; } } } if (left && right) { ans.push_back('1'); } else { ans.push_back('0'); } } return ans; } int main() { int tests; cin >> tests; for (int i = 0; i < tests; ++i) { int t; cin >> t; string s; cin >> s; cout << solve_stupid(t - 1, s) << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...