제출 #612243

#제출 시각아이디문제언어결과실행 시간메모리
612243drdilyor괄호 문자열 (CEOI16_match)C++17
10 / 100
22 ms340 KiB
#include <bits/stdc++.h> #ifdef ONPC #include "t_debug.cpp" #else #define debug(...) 42 #endif #define sz(a) ((int)(a).size()) using namespace std; using ll = long long; const int INF = 1e9; const ll INFL = 1e18; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rng(RANDOM); template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; } const int N = 2e5, LOGN = 17, MOD = 1e9+7; int solve(istream& cin, ostream& cout) { string s; if (!(cin >> s)) { return 1; } int n = s.size(); string res(n, '?'); auto valid = [&](int i, int j) { map<char,int> count; for (int k = i; k <= j; k++) { count[s[i]]++; } for (auto[k, v] : count) { if (v%2) return false; } int depth = 0; for (; i <= j; i++) { if (res[i] =='(')depth++; if (res[i] == ')')depth--; } return depth == 0; }; for (int i = 0; i < n; i++) { if (res[i] != '?') continue; for (int j = n-1; j > i; j--) { if (s[i] != s[j]) continue; if (res[j] != '?') continue; if (valid(i+1, j-1)) { res[i] = '('; res[j] = ')'; break; } } if (res[i] == '?') { cout << "-1\n"; return 0; } } cout << res << '\n'; return 0; } signed main() { int t = 1; #ifdef ONPC t = 10000; #endif while (t-- && cin) { #ifdef ONPC if (solve(cin, cout)) break; cout << "____________________" << endl; #else ifstream fin("match.in"); ofstream fout("match.out"); solve(cin, cout); break; #endif } return 0; } /* █████ █████ ███ ████ ▒▒███ ▒▒███ ▒▒▒ ▒▒███ ███████ ████████ ███████ ████ ▒███ █████ ████ ██████ ████████ ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███ ▒███ ▒▒███ ▒███ ███▒▒███▒▒███▒▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒████████ █████ ▒▒████████ █████ █████ ▒▒███████ ▒▒██████ █████ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒███ ▒▒▒▒▒▒ ▒▒▒▒▒ ███ ▒███ ▒▒██████ ▒▒▒▒▒▒ */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...