# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
62219 | 2018-07-27T21:57:50 Z | kingpig9 | 괄호 문자열 (CEOI16_match) | C++11 | 2000 ms | 1200 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define debug(...) fprintf(stderr, __VA_ARGS__) #define fi first #define se second #define all(v) (v).begin(), (v).end() #define fillchar(a, s) memset((a), (s), sizeof(a)) int N; string S; string ans; bool good (string seq) { stack<int> stk; for (int i = 0; i < seq.size(); i++) { if (seq[i] == '(') { stk.push(i); } else { if (stk.empty() || S[stk.top()] != S[i]) { return false; } stk.pop(); } } for (int i = seq.size(); i < N; i++) { //see if you can assign more stuff if (!stk.empty() && S[stk.top()] == S[i]) { stk.pop(); } else { stk.push(i); } } return stk.empty(); } int main() { if (fopen("match.in", "r")) { freopen("match.in", "r", stdin); freopen("match.out", "w", stdout); } cin >> S; N = S.size(); if (!good("")) { cout << "-1\n"; return 0; } for (int i = 0; i < N; i++) { ans += '('; if (!good(ans)) { ans.back() = ')'; } } cout << ans << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 3 ms | 492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 3 ms | 492 KB | Output is correct |
4 | Correct | 7 ms | 496 KB | Output is correct |
5 | Correct | 7 ms | 504 KB | Output is correct |
6 | Correct | 11 ms | 552 KB | Output is correct |
7 | Correct | 22 ms | 576 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 492 KB | Output is correct |
3 | Correct | 3 ms | 492 KB | Output is correct |
4 | Correct | 7 ms | 496 KB | Output is correct |
5 | Correct | 7 ms | 504 KB | Output is correct |
6 | Correct | 11 ms | 552 KB | Output is correct |
7 | Correct | 22 ms | 576 KB | Output is correct |
8 | Correct | 319 ms | 740 KB | Output is correct |
9 | Correct | 407 ms | 768 KB | Output is correct |
10 | Correct | 260 ms | 768 KB | Output is correct |
11 | Correct | 192 ms | 800 KB | Output is correct |
12 | Execution timed out | 2049 ms | 1200 KB | Time limit exceeded |
13 | Halted | 0 ms | 0 KB | - |