Submission #810484

#TimeUsernameProblemLanguageResultExecution timeMemory
810484bonkSuperpozicija (COCI22_superpozicija)C++14
10 / 110
19 ms2988 KiB
#include <bits/stdc++.h> using namespace std; bool valid(string s){ int sum = 0; for(int i = 0; i < s.length(); i++){ if(s[i] == '(') sum++; else{ sum--; if(sum < 0) return false; } } return (sum == 0); } void solve(){ //subtask 2 int n; cin >> n; string s; cin >> s; vector<pair<int, int>>v(n); string cur = ""; vector<int>tmp; for(int i = 0; i < n; i++){ cin >> v[i].first >> v[i].second; v[i].first--; v[i].second--; if(s[v[i].first] == '(') tmp.push_back(v[i].first); else tmp.push_back(v[i].second); } sort(tmp.begin(), tmp.end()); for(auto &x: tmp) cur += s[x]; if(valid(cur)){ for(int i = 0; i < n; i++){ if(s[v[i].first] == '(') cout << 0 << ' '; else cout << 1 << ' '; } cout << '\n'; } else{ cout << -1 << '\n'; } return; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc; cin >> tc; while(tc--){ solve(); } return 0; }

Compilation message (stderr)

Main.cpp: In function 'bool valid(std::string)':
Main.cpp:7:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int i = 0; i < s.length(); 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...