Submission #198213

#TimeUsernameProblemLanguageResultExecution timeMemory
198213parsa_mobedMatch (CEOI16_match)C++14
37 / 100
2100 ms664 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N], n; string s; bool isval() { vector <char> vec; for (int i = 0; i < n; i++) { if (a[i] == -1) { if (vec.empty() || vec.back() != s[i]) return 0; vec.pop_back(); } if (a[i] == 1) vec.push_back(s[i]); if (a[i] == 0) { if (vec.size() && vec.back() == s[i]) vec.pop_back(); else vec.push_back(s[i]); } } return vec.empty(); } int main() { cin >> s; n = s.size(); if (!isval()) return cout << -1 << "\n", 0; for (int i = 0; i < n; i++) { a[i] = 1; if (!isval()) a[i] = -1; } for (int i = 0; i < n; i++) cout << (a[i] == 1 ? '(' : ')'); cout << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...