# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
666811 | Hacv16 | Superpozicija (COCI22_superpozicija) | C++17 | 248 ms | 516 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e6 + 50;
const int INF = 0x3f3f3f3f;
int tc, n, a[MAX], b[MAX];
string s;
bool valid(string& t){
stack<char> s;
for(int i = 0; i < t.size(); i++){
if(t[i] == ')'){
if(s.empty()) return false;
else s.pop();
}else{
s.push('(');
}
}
if(s.size()) return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> tc;
while(tc--){
cin >> n >> s;
for(int i = 0; i < n; i++)
cin >> a[i] >> b[i];
for(int i = 0; i < n; i++) a[i]--, b[i]--;
int ans = -1;
for(int mask = 0; mask < (1 << n); mask++){
string cur = "";
for(int i = 0; i < n; i++){
if(mask & (1 << i)) cur += s[a[i]];
else cur += s[b[i]];
}
if(valid(cur)){
ans = mask; break;
}
}
if(ans == -1){
cout << -1 << '\n';
}else{
for(int i = 0; i < n; i++)
cout << (ans & (1 << i) ? 0 : 1) << ' ';
cout << '\n';
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |