# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236763 | 2020-06-03T09:00:10 Z | Sorting | Match (CEOI16_match) | C++14 | 2000 ms | 512 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Execution timed out | 2041 ms | 384 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Execution timed out | 2041 ms | 384 KB | Time limit exceeded |
5 | Halted | 0 ms | 0 KB | - |