# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
52914 | 2018-06-27T07:19:49 Z | 김세빈(#1383) | 괄호 문자열 (CEOI16_match) | C++11 | 13 ms | 572 KB |
#include <bits/stdc++.h> using namespace std; char str[101010], ans[101010]; vector <char> V; int n; bool check(int p) { int i; V.clear(); for(i=0;i<=p;i++){ if(ans[i] == '(') V.push_back(str[i]); else V.pop_back(); } for(;i<n;i++){ if(V.empty() || V.back() != str[i]) V.push_back(str[i]); else V.pop_back(); } return V.empty(); } int main() { int i; scanf("%s",str); for(n=0;str[n];n++); if(n > 2000) return 0; ans[0] = '('; if(!check(0)){ printf("-1\n"); return 0; } for(i=0;i<n;i++){ ans[i] = '('; if(!check(i)) ans[i] = ')'; } ans[n] = '\0'; printf("%s\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 5 ms | 492 KB | Output is correct |
5 | Correct | 4 ms | 492 KB | Output is correct |
6 | Correct | 7 ms | 528 KB | Output is correct |
7 | Correct | 13 ms | 528 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 492 KB | Output is correct |
4 | Correct | 5 ms | 492 KB | Output is correct |
5 | Correct | 4 ms | 492 KB | Output is correct |
6 | Correct | 7 ms | 528 KB | Output is correct |
7 | Correct | 13 ms | 528 KB | Output is correct |
8 | Incorrect | 2 ms | 572 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |