Submission #968439

#TimeUsernameProblemLanguageResultExecution timeMemory
968439IsamSuperpozicija (COCI22_superpozicija)C++17
10 / 110
16 ms3896 KiB
#include<bits/stdc++.h> using namespace std; int n, l[100100], r[100100]; string z; int ans[100100]; int gr[200200]; set<pair<int, int>> st, sto; signed main(){ ios_base::sync_with_stdio(0), cin.tie(0); int T; cin >> T; function<void()> test_case = [](){ cin >> n >> z; st.clear(); z = '.' + z; for(register int i = 1; i <= n; ++i){ cin >> l[i] >> r[i]; gr[l[i]] = r[i]; gr[r[i]] = l[i]; if(z[l[i]] == '(' && z[r[i]] == '('){ ans[i] = 0; z[r[i]] = '.'; }else if(z[l[i]] == ')' && z[r[i]] == ')'){ ans[i] = 1; z[l[i]] = '.'; }else if(z[l[i]] == '(' && z[r[i]] == ')'){ st.insert({l[i], i}); z[l[i]] = '.'; ans[i] = 1; }else{ // ) ( st.insert({r[i], i}); z[r[i]] = '.'; ans[i] = 0; } } if(n & 1) return cout << -1 << '\n', void(); int tot(0); for(register int i = 1; i <= n * 2; ++i){ if(z[i] != '.') tot += (z[i]=='('?1:-1); auto it = st.begin(); while(it != st.end() && it->first <= i){ sto.insert({gr[it->first], it->second}); st.erase(it); ++it; } while(tot < 0 && !sto.empty()){ auto itr = sto.begin(); int pos = itr->first, j = itr->second; pos = gr[pos]; z[pos] = '(', ++tot; if(gr[pos] <= i){ ++tot; } z[gr[pos]] = '.'; ans[j] ^= 1; sto.erase(itr); } //if(tot < 0) return cout << -1 << '\n', void(); } // cerr<<"gnrem"<<endl; /* while(tot < 0 && !sto.empty()){ auto itr = sto.begin(); int pos = itr->first, j = itr->second; pos = gr[pos]; z[pos] = '(', ++tot; ++tot; z[gr[pos]] = '.'; ans[j] ^= 1; sto.erase(itr); } if(tot != 0) return cout << -1 << '\n', void(); */ function<bool(const string)> is_valid = [](const string &s){ int tot(0); for(register int i = 0; i < (int)s.size(); ++i){ tot += (s[i]=='('?1:-1); if(tot < 0) return false; } return !tot; }; string tmp = ""; for(register int i = 1; i <= 2*n; ++i){ if(z[i] == '.') continue; tmp += z[i]; } if(is_valid(tmp)){ for(register int i = 1; i <= n; ++i) cout << ans[i] << ' '; }else{ cout << -1; } cout << '\n'; }; while(T--) test_case(); return 0; }

Compilation message (stderr)

Main.cpp: In lambda function:
Main.cpp:23:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   23 |   for(register int i = 1; i <= n; ++i){
      |                    ^
Main.cpp:50:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   50 |   for(register int i = 1; i <= n * 2; ++i){
      |                    ^
Main.cpp: In lambda function:
Main.cpp:120:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  120 |    for(register int i = 0; i < (int)s.size(); ++i){
      |                     ^
Main.cpp: In lambda function:
Main.cpp:130:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  130 |   for(register int i = 1; i <= 2*n; ++i){
      |                    ^
Main.cpp:136:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  136 |    for(register int i = 1; i <= n; ++i) cout << ans[i] << ' ';
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...