# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
810484 | 2023-08-06T10:10:58 Z | bonk | Superpozicija (COCI22_superpozicija) | C++14 | 19 ms | 2988 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 980 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 1100 KB | Output is correct |
2 | Correct | 17 ms | 1664 KB | Output is correct |
3 | Correct | 16 ms | 1736 KB | Output is correct |
4 | Correct | 18 ms | 2108 KB | Output is correct |
5 | Correct | 16 ms | 2232 KB | Output is correct |
6 | Correct | 10 ms | 1940 KB | Output is correct |
7 | Correct | 12 ms | 2196 KB | Output is correct |
8 | Correct | 17 ms | 2516 KB | Output is correct |
9 | Correct | 17 ms | 2888 KB | Output is correct |
10 | Correct | 19 ms | 2988 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 16 ms | 980 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |