Submission #390718

#TimeUsernameProblemLanguageResultExecution timeMemory
390718Vladth11Match (CEOI16_match)C++14
37 / 100
2071 ms37060 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define debug(x) cerr << #x << " " << x << "\n" #define debug_with_space(x) cerr << #x << " " << x << " " using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair <ll, ll> pii; typedef pair <long double, pii> muchie; typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST; const ll NMAX = 100001; const ll INF = (1LL << 60); const ll MOD = 1000000007; const ll BLOCK = 225; const ll base = 31; const ll nr_of_bits = 21; class Hashes { ll base, mod; public: ll value = 0; Hashes(ll _base, ll _MOD) { base = _base; mod = _MOD; } ll lgput(ll n, ll p) { ll r = 1; while(p) { if(p % 2) { r *= n; r %= mod; } n *= n; n %= mod; p /= 2; } return r; } void insert(ll x) { value = value * base; value += x; value %= mod; } void erase(ll x) { value -= x; if(value < 0) { value += mod; } value = (value * lgput(base, mod - 2)) % mod; } } H(31, MOD); int inainte[NMAX]; int dupa[NMAX]; set <int> v[28]; string rez; string s; void solve(int l, int r) { int pz; if(l > r) return; stack <int> st; int last = 8; if(st.empty() && s[l] == s[l + 1] && rez[l + 1] != '(' && rez[l + 1] != ')') last = l + 1; for(ll i = l + 1; i < r; i++) { ll c = s[i] - 'a' + 1; if(st.size() && st.top() == c) { st.pop(); } else { st.push(c); } if(st.empty() && s[l] == s[i + 1]) last = i + 1; } rez[last] = ')'; rez[l] = '('; solve(l + 1, last - 1); solve(last + 1, r); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> s; rez = s; stack <ll> st; for(ll i = 0; i < s.size(); i++) { ll c = s[i] - 'a' + 1; v[c].insert(i); inainte[i] = H.value; if(st.size() && st.top() == c) { H.erase(st.top()); st.pop(); } else { H.insert(c); st.push(c); } dupa[i] = H.value; } if(st.size()) { cout << -1; return 0; } solve(0, s.size() - 1); cout << rez; return 0; }

Compilation message (stderr)

match.cpp: In function 'void solve(int, int)':
match.cpp:63:9: warning: unused variable 'pz' [-Wunused-variable]
   63 |     int pz;
      |         ^~
match.cpp: In function 'int main()':
match.cpp:93:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for(ll i = 0; i < s.size(); i++) {
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...