# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
730713 | 2023-04-26T10:23:41 Z | Augustyn | Superpozicija (COCI22_superpozicija) | C++17 | 29 ms | 2476 KB |
#include<bits/stdc++.h> using namespace std; #define f first #define s second pair<int,int>ab[100001]; char naw[100001]; int jb[100001],gr[100001]; int t,n; void rozw() { scanf("%d",&n); priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>dod; char wcz=getchar(); while(wcz!='('&&wcz!=')') wcz=getchar(); for(int i=0;i<(n<<1);++i) { naw[i]=wcz; wcz=getchar(); } for(int i=0;i<n;++i) { scanf("%d%d",&ab[i].f,&ab[i].s); --ab[i].f; --ab[i].s; gr[ab[i].f]=ab[i].s; gr[ab[i].s]=ab[i].f; } int ile=0; for(int i=0;i<2*n;++i) { if(naw[gr[i]]==naw[i]) { if(naw[i]=='('&&i<gr[i]) { jb[i]=t; jb[gr[i]]=-t; ++ile; } else if(naw[i]==')'&&i>gr[i]) { jb[i]=t; jb[gr[i]]=-t; --ile; } } else { if(jb[i]!=-t&&jb[i]!=t) { if(naw[i]=='(') { jb[i]=-t; jb[gr[i]]=t; dod.push({gr[i],i}); } else { jb[i]=t; jb[gr[i]]=-t; --ile; dod.push({gr[i],i}); } } else { if(jb[i]==t) { if(naw[i]==')') --ile; else ++ile; } } } if(ile<0) { if(dod.empty()) { printf("-1\n"); return; } jb[dod.top().s]*=-1; jb[dod.top().f]*=-1; ++ile; if(max(dod.top().f,dod.top().s)<=i) ++ile; dod.pop(); } } if(ile!=0) { printf("-1\n"); return; } for(int i=0;i<n;++i) { if(jb[ab[i].f]==t) printf("0 "); else printf("1 "); } printf("\n"); } int main() { ios_base::sync_with_stdio(0); scanf("%d",&t); while(t) { rozw(); --t; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 468 KB | Output is correct |
2 | Correct | 23 ms | 348 KB | Output is correct |
3 | Correct | 24 ms | 556 KB | Output is correct |
4 | Correct | 29 ms | 408 KB | Output is correct |
5 | Correct | 23 ms | 444 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 468 KB | Output is correct |
2 | Correct | 19 ms | 600 KB | Output is correct |
3 | Correct | 17 ms | 724 KB | Output is correct |
4 | Correct | 26 ms | 980 KB | Output is correct |
5 | Correct | 17 ms | 1356 KB | Output is correct |
6 | Correct | 11 ms | 1604 KB | Output is correct |
7 | Correct | 15 ms | 2052 KB | Output is correct |
8 | Correct | 21 ms | 2348 KB | Output is correct |
9 | Correct | 21 ms | 2384 KB | Output is correct |
10 | Correct | 28 ms | 2476 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 19 ms | 404 KB | Output is correct |
3 | Correct | 19 ms | 676 KB | Output is correct |
4 | Correct | 24 ms | 992 KB | Output is correct |
5 | Correct | 26 ms | 1236 KB | Output is correct |
6 | Correct | 22 ms | 1652 KB | Output is correct |
7 | Correct | 10 ms | 1188 KB | Output is correct |
8 | Incorrect | 19 ms | 2028 KB | Output isn't correct |
9 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 468 KB | Output is correct |
2 | Correct | 23 ms | 348 KB | Output is correct |
3 | Correct | 24 ms | 556 KB | Output is correct |
4 | Correct | 29 ms | 408 KB | Output is correct |
5 | Correct | 23 ms | 444 KB | Output is correct |
6 | Correct | 19 ms | 468 KB | Output is correct |
7 | Correct | 19 ms | 600 KB | Output is correct |
8 | Correct | 17 ms | 724 KB | Output is correct |
9 | Correct | 26 ms | 980 KB | Output is correct |
10 | Correct | 17 ms | 1356 KB | Output is correct |
11 | Correct | 11 ms | 1604 KB | Output is correct |
12 | Correct | 15 ms | 2052 KB | Output is correct |
13 | Correct | 21 ms | 2348 KB | Output is correct |
14 | Correct | 21 ms | 2384 KB | Output is correct |
15 | Correct | 28 ms | 2476 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 19 ms | 404 KB | Output is correct |
18 | Correct | 19 ms | 676 KB | Output is correct |
19 | Correct | 24 ms | 992 KB | Output is correct |
20 | Correct | 26 ms | 1236 KB | Output is correct |
21 | Correct | 22 ms | 1652 KB | Output is correct |
22 | Correct | 10 ms | 1188 KB | Output is correct |
23 | Incorrect | 19 ms | 2028 KB | Output isn't correct |
24 | Halted | 0 ms | 0 KB | - |