Submission #1243804

#TimeUsernameProblemLanguageResultExecution timeMemory
1243804yassiaMatch (CEOI16_match)C++20
0 / 100
0 ms324 KiB
#ifndef local #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using pii = pair<int, int>; using pll = pair<ll,ll>; using str = string; using ld = long double; using hash_map =gp_hash_table<int, int>; using hash_set= gp_hash_table <int, null_type>; auto sd = std::chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rnd(sd); typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ord_set; const ll maxn = 3e5+8; const ll inf = 2e18+7; const ll logn = 16; const ll mod = 1e9+7; void solve1() { str s; cin>>s; str seq; vector<pair<char,char>> st; ll n = s.size(); map<char,ll> opened; map<ll,ll> cnt; for (auto &x: s)cnt[x]++; for (int i = 0; i < n; i++){ cnt[s[i]]--; bool fnd =false; for (int j = i+1; j < n; j++){ if(s[i]==s[j]&&(j-i-1)%2==0){ fnd =true; break; } } if (fnd && opened[s[i]]+1 <= cnt[s[i]]){ st.push_back({'(',s[i]}); seq.push_back('('); opened[s[i]]++; } else { if (st.empty()|| st.back()!=make_pair('(',s[i])){ cout<<-1<<endl; return; } st.pop_back(); seq.push_back(')'); opened[s[i]]--; } } if (!st.empty()){ cout<<-1<<endl; return; } cout<<seq; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef local freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif solve1(); #ifdef local printf_s("\n%.5f s", (double) clock() / CLOCKS_PER_SEC); #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...