# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43847 | 2018-03-25T11:56:33 Z | ngkan146 | Match (CEOI16_match) | C++11 | 1 ms | 356 KB |
#include <bits/stdc++.h> using namespace std; string s; int cnt[256], cnt2[256]; int main(){ iostream::sync_with_stdio(0); cin >> s; for(auto v: s) ++ cnt[v]; for(auto v: cnt){ if (cnt[v] % 2){ cout << -1; exit(0); } } string res; for(auto v: s){ res.push_back((++cnt2[v] <= cnt[v]/2 ? '(' : ')')); } // check stack <char> st; for(int i=0;i<res.size();i++){ if (res[i] == '(') st.push(s[i]); else{ if (st.top() != s[i]){ cout << -1; exit(0); } st.pop(); } } cout << res; // }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 248 KB | Output is correct |
2 | Incorrect | 1 ms | 356 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 248 KB | Output is correct |
2 | Incorrect | 1 ms | 356 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 248 KB | Output is correct |
2 | Incorrect | 1 ms | 356 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |