Submission #705016

#TimeUsernameProblemLanguageResultExecution timeMemory
705016guagua0407Superpozicija (COCI22_superpozicija)C++17
0 / 110
449 ms448 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define all(x) x.begin(),x.end() int trans(char a){ return (a=='('?1:-1); } void solve(){ int n; cin>>n; string str; cin>>str; vector<pair<int,int>> num(n); for(int i=0;i<n;i++){ cin>>num[i].f>>num[i].s; num[i].f--; num[i].s--; } for(int i=0;i<(1<<n);i++){ vector<int> ans; vector<pair<int,int>> cur; for(int j=0;j<n;j++){ if(i&(1<<j)){ ans.push_back(1); cur.push_back({num[j].s,trans(str[num[j].s])}); } else{ ans.push_back(0); cur.push_back({num[j].f,trans(str[num[j].f])}); } } sort(all(cur)); bool tf=true; int cnt=0; for(int i=0;i<n;i++){ cnt+=cur[i].s; if(cnt<0) tf=false; } if(tf and cnt==0){ for(int i=0;i<n;i++){ cout<<ans[i]<<' '; } return; } } cout<<-1; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ solve(); cout<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...