# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1032675 | 2024-07-24T06:04:05 Z | 김은성(#10965) | 괄호 문자열 (CEOI16_match) | C++17 | 2000 ms | 740 KB |
#include <bits/stdc++.h> using namespace std; char s[100009], t[100009]; int cnt[128], cur[128]; int n; bool possible(int idx, vector<char> st){ int i; for(i=idx; i<n; i++){ if(!st.empty() && st.back() == s[i]) st.pop_back(); else st.push_back(s[i]); } return st.empty(); } int main(){ int i; scanf(" %s", s); n = strlen(s); for(i=0; i<n; i++) cnt[s[i]]++; vector<char> st; if(!possible(0, st)){ printf("-1\n"); return 0; } for(i=0; i<n; i++){ st.push_back(s[i]); t[i] = '('; if(st.size()>1 && st[st.size()-2] == s[i]){ if(cur[s[i]] >= cnt[s[i]]/2 || !possible(i+1, st)){ t[i] = ')'; cur[s[i]] -= 2; st.pop_back(); st.pop_back(); } } cur[s[i]]++; } printf("%s\n", t); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 2 ms | 348 KB | Output is correct |
7 | Correct | 3 ms | 448 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 2 ms | 348 KB | Output is correct |
7 | Correct | 3 ms | 448 KB | Output is correct |
8 | Correct | 22 ms | 348 KB | Output is correct |
9 | Correct | 28 ms | 348 KB | Output is correct |
10 | Correct | 22 ms | 344 KB | Output is correct |
11 | Correct | 22 ms | 348 KB | Output is correct |
12 | Correct | 1375 ms | 584 KB | Output is correct |
13 | Correct | 1489 ms | 712 KB | Output is correct |
14 | Execution timed out | 2041 ms | 740 KB | Time limit exceeded |
15 | Halted | 0 ms | 0 KB | - |