Submission #604441

#TimeUsernameProblemLanguageResultExecution timeMemory
604441AleeeMatch (CEOI16_match)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define all(a) (a).begin(), (a).end() #define endl '\n' #define forn(i, l, n) for (int i = l; i < int(n); i++) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; const int INF = 1e9 + 7; string solve(string str, int pos, int test, string ans, stack<char> st) { if (pos >= str.length() && test == 0) return ans; if (pos >= str.length()) return ""; if (test < 0) return ""; if (st.empty()) { ans += "("; st.push(str[pos]); test++; return solve(str, pos + 1, test, ans, st); } if (st.top() != str[pos]) { ans += "("; st.push(str[pos]); test++; return solve(str, pos + 1, test, ans, st); } else { string a = ""; if (str[pos + 1] == str[pos]) { st.push(str[pos]); a = solve(str, pos + 1, test + 1, ans + "(", st); st.pop(); } st.pop(); string b = solve(str, pos + 1, test - 1, ans + ")", st); if (a.size() || b.size()) { if (a.size()) return a; else return b; } else return ""; } } int main() // Ale C. { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("output.txt", "w", stdout); string str; cin >> str; if (str.length() % 2 != 0) { cout << -1; return 0; } string ans = solve(str, 0, 0, "", stack<char>()); cout << (ans.length() ? ans : "-1"); return 0; }

Compilation message (stderr)

match.cpp: In function 'std::string solve(std::string, int, int, std::string, std::stack<char>)':
match.cpp:17:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   if (pos >= str.length() && test == 0)
      |       ~~~~^~~~~~~~~~~~~~~
match.cpp:19:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |   if (pos >= str.length())
      |       ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...