# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
236763 | 2020-06-03T09:00:10 Z | Sorting | 괄호 문자열 (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
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | - |
# | 결과 | 실행 시간 | 메모리 | 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 | - |