Submission #1117845

#TimeUsernameProblemLanguageResultExecution timeMemory
1117845vjudge1괄호 문자열 (CEOI16_match)C++17
0 / 100
1 ms336 KiB
// Author RufatM #include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1e9+7 #define ll long long #define ull unsigned long long #define vi vector<int> #define vii vector<vector<int>> #define mii map<int,int> #define pb push_back #define pii pair<ll,int> #define all(a) a.begin(),a.end() #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); signed main(){ int t=1; //cin >> t; while(t--){ fastio; string S; cin >> S; int N = S.length(); vector<char> B(N); stack<pair<char,int>> st; for(int i = 0; i < N; i++) { char c = S[i]; if(!st.empty() && st.top().first == c) { B[st.top().second] = '('; B[i] = ')'; st.pop(); } else { st.push({c, i}); } } if(!st.empty()) { cout << "-1\n"; return 0; } int balance = 0; for(int i = 0; i < N; i++) { if(B[i] == '(') balance++; else if(B[i] == ')') balance--; else { cout << "-1\n"; return 0; } if(balance < 0) { cout << "-1\n"; return 0; } } if(balance != 0) { cout << "-1\n"; return 0; } for(int i = 0; i < N; i++) { cout << B[i]; } cout << '\n'; } } //Allahim insallah tle vermez //Yasasin Yaxsi Kiwiler //Yasasin Info Azerbaijan
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...