Submission #236763

#TimeUsernameProblemLanguageResultExecution timeMemory
236763SortingMatch (CEOI16_match)C++14
10 / 100
2041 ms512 KiB
#include <bits/stdc++.h> using namespace std; string s; int n; bool solve(string &answer, int pos){ if(answer == "" && pos == n) return true; if(answer.size() > (n - pos)) return false; answer += s[pos]; if(solve(answer, pos + 1)){ answer += "("; return true; } answer.pop_back(); if(answer != "" && answer.back() == s[pos]){ answer.pop_back(); if(solve(answer, pos + 1)){ answer += ")"; return true; } answer += s[pos]; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> s; n = s.size(); string answer = ""; if(solve(answer, 0)){ reverse(answer.begin(), answer.end()); cout << answer << "\n"; } else cout << "-1\n"; }

Compilation message (stderr)

match.cpp: In function 'bool solve(std::__cxx11::string&, int)':
match.cpp:11:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(answer.size() > (n - pos))
        ~~~~~~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...