# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1117729 | 2024-11-24T07:52:07 Z | vjudge1 | 괄호 문자열 (CEOI16_match) | C++17 | 2 ms | 336 KB |
/* #ifndef ONLINE_JUDGE #include "AkbarKING.h" // aska geldi akbarking.h #else #define debug(...) #define debugArr(...) #define debugG(...) #endif */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> #define int long long #define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr); #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #define ep emplace_back #define pb push_back #define pii pair<int,int> #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() using namespace std; using namespace __gnu_pbds; template <typename T> using __indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using __indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; const int sz = 3e5+9; const int LOG = 63; const int MOD = 1e9+7; const int INF = 1e18; string s; bool check() { if ((int)s.length() & 1) { cout<<"-1\n"; return 0; } stack<int>st; for (int i = 0; i < (int)s.length(); ++i) { if (!st.empty() && s[st.top()] == s[i]) { st.pop(); } else { st.push(i); } } if (!st.empty()) { cout<<"-1\n"; return 0; } return 1; } void solve() { cin>>s; if (check()) { string res = ""; stack<int>st; for (int i = 0; i < (int)s.length(); ++i) { stack<int>nwst = st; nwst.push(i); for (int j = i + 1; j < (int)s.length(); ++j) { if (!nwst.empty() && s[j] == s[nwst.top()]) { nwst.pop(); } else { nwst.push(j); } } if (nwst.empty()) { res += "("; st.push(i); } else { res += ")"; st.pop(); } } cout<<res<<'\n'; } } signed main() { $AzH_TxdmN$ freopen("match.in", "r", stdin); freopen("match.out", "w", stdout); int t = 1; //cin>>t; while (t--) { solve(); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 336 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 336 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 336 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |