# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
12828 |
2015-01-09T12:49:55 Z |
ainta |
전선 연결하기 (GA9_wire) |
C++ |
|
596 ms |
39632 KB |
#include<stdio.h>
#include<algorithm>
using namespace std;
#define SZ 1048576
int n, chk[301000], num[601000];
int st[601000];
struct IdxTree{
int r, l;
}IT[SZ + SZ + 1];
struct point{
int b, e;
}w[301000];
void UDT(int x){
while (x != 1){
x >>= 1;
if (w[IT[x * 2].l].b <= w[IT[x * 2 + 1].l].b)IT[x].l = IT[x * 2].l;
else IT[x].l = IT[x * 2 + 1].l;
if (w[IT[x * 2].r].e >= w[IT[x * 2 + 1].r].e)IT[x].r = IT[x * 2].r;
else IT[x].r = IT[x * 2 + 1].r;
}
}
void Ins(int x, int a){
x += SZ;
IT[x].l = IT[x].r = a;
UDT(x);
}
void Del(int x){
x += SZ;
IT[x].l = IT[x].r = 0;
UDT(x);
}
int Left(int b, int e){
int r = 0;
b += SZ, e += SZ;
while (b <= e){
if (w[r].b > w[IT[b].l].b)r = IT[b].l;
if (w[r].b > w[IT[e].l].b)r = IT[e].l;
b = (b + 1) >> 1, e = (e - 1) >> 1;
}
return r;
}
int Right(int b, int e){
int r = 0;
b += SZ, e += SZ;
while (b <= e){
if (w[r].e < w[IT[b].r].e)r = IT[b].r;
if (w[r].e < w[IT[e].r].e)r = IT[e].r;
b = (b + 1) >> 1, e = (e - 1) >> 1;
}
return r;
}
bool Check(int ck){
int i, top = 0;
for (i = 1; i <= 2 * n; i++){
if (chk[num[i]] != ck)continue;
if (st[top] == num[i])top--;
else st[++top] = num[i];
}
if (top)return false;
return true;
}
void DFS(int a, int b){
chk[a] = b;
int i, l, r;
Del(w[a].b);
Del(w[a].e);
while (1){
l = Left(w[a].b, w[a].e);
if (w[l].b < w[a].b)DFS(l, 3 - b);
else break;
}
while (1){
r = Right(w[a].b, w[a].e);
if (w[r].e > w[a].e)DFS(r, 3 - b);
else break;
}
}
int main(){
int i, a, t;
scanf("%d", &n);
w[0].b = 2 * n + 1, w[1].e = 0;
for (i = 1; i <= 2 * n; i++){
scanf("%d", &a);
num[i] = a;
if (!w[a].b)w[a].b = i;
else w[a].e = i;
}
for (i = 1; i <= n; i++){
Ins(w[i].b, i);
Ins(w[i].e, i);
}
for (i = 1; i <= n; i++){
if (!chk[i]){
DFS(i, 1);
}
}
if (Check(1) && Check(2)){
for (i = 1; i <= 2 * n; i++){
if (chk[num[i]] == 1)printf("^");
else printf("v");
}
}
else printf("IMPOSSIBLE\n");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
25692 KB |
Output is correct |
2 |
Correct |
0 ms |
25692 KB |
Output is correct |
3 |
Correct |
0 ms |
25692 KB |
Output is correct |
4 |
Correct |
0 ms |
25692 KB |
Output is correct |
5 |
Correct |
0 ms |
25692 KB |
Output is correct |
6 |
Correct |
0 ms |
25692 KB |
Output is correct |
7 |
Correct |
0 ms |
25692 KB |
Output is correct |
8 |
Correct |
0 ms |
25692 KB |
Output is correct |
9 |
Correct |
0 ms |
25692 KB |
Output is correct |
10 |
Correct |
0 ms |
25692 KB |
Output is correct |
11 |
Correct |
0 ms |
25692 KB |
Output is correct |
12 |
Correct |
0 ms |
25692 KB |
Output is correct |
13 |
Correct |
0 ms |
25692 KB |
Output is correct |
14 |
Correct |
0 ms |
25692 KB |
Output is correct |
15 |
Correct |
0 ms |
25692 KB |
Output is correct |
16 |
Correct |
0 ms |
25692 KB |
Output is correct |
17 |
Correct |
0 ms |
25692 KB |
Output is correct |
18 |
Correct |
0 ms |
25692 KB |
Output is correct |
19 |
Correct |
0 ms |
25692 KB |
Output is correct |
20 |
Correct |
0 ms |
25692 KB |
Output is correct |
21 |
Correct |
0 ms |
25692 KB |
Output is correct |
22 |
Correct |
0 ms |
25692 KB |
Output is correct |
23 |
Correct |
0 ms |
25692 KB |
Output is correct |
24 |
Correct |
0 ms |
25692 KB |
Output is correct |
25 |
Correct |
0 ms |
25692 KB |
Output is correct |
26 |
Correct |
0 ms |
25692 KB |
Output is correct |
27 |
Correct |
0 ms |
25692 KB |
Output is correct |
28 |
Correct |
0 ms |
25692 KB |
Output is correct |
29 |
Correct |
0 ms |
25692 KB |
Output is correct |
30 |
Correct |
0 ms |
25692 KB |
Output is correct |
31 |
Correct |
0 ms |
25692 KB |
Output is correct |
32 |
Correct |
0 ms |
25692 KB |
Output is correct |
33 |
Correct |
0 ms |
25692 KB |
Output is correct |
34 |
Correct |
0 ms |
25692 KB |
Output is correct |
35 |
Correct |
0 ms |
25692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
25692 KB |
Output is correct |
2 |
Correct |
0 ms |
25692 KB |
Output is correct |
3 |
Correct |
0 ms |
25692 KB |
Output is correct |
4 |
Correct |
0 ms |
25692 KB |
Output is correct |
5 |
Correct |
0 ms |
25692 KB |
Output is correct |
6 |
Correct |
0 ms |
25692 KB |
Output is correct |
7 |
Correct |
0 ms |
25692 KB |
Output is correct |
8 |
Correct |
0 ms |
25692 KB |
Output is correct |
9 |
Correct |
0 ms |
25692 KB |
Output is correct |
10 |
Correct |
0 ms |
25692 KB |
Output is correct |
11 |
Correct |
0 ms |
25692 KB |
Output is correct |
12 |
Correct |
0 ms |
25692 KB |
Output is correct |
13 |
Correct |
0 ms |
25692 KB |
Output is correct |
14 |
Correct |
0 ms |
25692 KB |
Output is correct |
15 |
Correct |
0 ms |
25692 KB |
Output is correct |
16 |
Correct |
0 ms |
25692 KB |
Output is correct |
17 |
Correct |
0 ms |
25692 KB |
Output is correct |
18 |
Correct |
0 ms |
25692 KB |
Output is correct |
19 |
Correct |
0 ms |
25692 KB |
Output is correct |
20 |
Correct |
0 ms |
25692 KB |
Output is correct |
21 |
Correct |
0 ms |
25692 KB |
Output is correct |
22 |
Correct |
0 ms |
25692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
25692 KB |
Output is correct |
2 |
Correct |
16 ms |
25692 KB |
Output is correct |
3 |
Correct |
92 ms |
27724 KB |
Output is correct |
4 |
Correct |
92 ms |
25760 KB |
Output is correct |
5 |
Correct |
92 ms |
25692 KB |
Output is correct |
6 |
Correct |
68 ms |
25692 KB |
Output is correct |
7 |
Correct |
108 ms |
25692 KB |
Output is correct |
8 |
Correct |
8 ms |
25692 KB |
Output is correct |
9 |
Correct |
16 ms |
25692 KB |
Output is correct |
10 |
Correct |
88 ms |
26956 KB |
Output is correct |
11 |
Correct |
76 ms |
25696 KB |
Output is correct |
12 |
Correct |
64 ms |
25700 KB |
Output is correct |
13 |
Correct |
88 ms |
25692 KB |
Output is correct |
14 |
Correct |
80 ms |
25692 KB |
Output is correct |
15 |
Correct |
96 ms |
25700 KB |
Output is correct |
16 |
Correct |
16 ms |
25692 KB |
Output is correct |
17 |
Correct |
16 ms |
25692 KB |
Output is correct |
18 |
Correct |
92 ms |
27756 KB |
Output is correct |
19 |
Correct |
80 ms |
25700 KB |
Output is correct |
20 |
Correct |
136 ms |
25692 KB |
Output is correct |
21 |
Correct |
92 ms |
25772 KB |
Output is correct |
22 |
Correct |
96 ms |
25716 KB |
Output is correct |
23 |
Correct |
128 ms |
25692 KB |
Output is correct |
24 |
Correct |
124 ms |
25752 KB |
Output is correct |
25 |
Correct |
144 ms |
25692 KB |
Output is correct |
26 |
Correct |
136 ms |
25692 KB |
Output is correct |
27 |
Correct |
144 ms |
28692 KB |
Output is correct |
28 |
Correct |
148 ms |
28688 KB |
Output is correct |
29 |
Correct |
156 ms |
30256 KB |
Output is correct |
30 |
Correct |
140 ms |
30256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
236 ms |
25692 KB |
Output is correct |
2 |
Correct |
308 ms |
25908 KB |
Output is correct |
3 |
Correct |
232 ms |
25692 KB |
Output is correct |
4 |
Correct |
320 ms |
25792 KB |
Output is correct |
5 |
Correct |
364 ms |
25968 KB |
Output is correct |
6 |
Correct |
520 ms |
25696 KB |
Output is correct |
7 |
Correct |
500 ms |
26100 KB |
Output is correct |
8 |
Correct |
400 ms |
26024 KB |
Output is correct |
9 |
Correct |
268 ms |
25860 KB |
Output is correct |
10 |
Correct |
288 ms |
25692 KB |
Output is correct |
11 |
Correct |
340 ms |
25692 KB |
Output is correct |
12 |
Correct |
252 ms |
25856 KB |
Output is correct |
13 |
Correct |
500 ms |
26028 KB |
Output is correct |
14 |
Correct |
504 ms |
25692 KB |
Output is correct |
15 |
Correct |
252 ms |
25692 KB |
Output is correct |
16 |
Correct |
236 ms |
25696 KB |
Output is correct |
17 |
Correct |
264 ms |
25796 KB |
Output is correct |
18 |
Correct |
232 ms |
25880 KB |
Output is correct |
19 |
Correct |
384 ms |
25880 KB |
Output is correct |
20 |
Correct |
516 ms |
26004 KB |
Output is correct |
21 |
Correct |
528 ms |
25856 KB |
Output is correct |
22 |
Correct |
596 ms |
34940 KB |
Output is correct |
23 |
Correct |
588 ms |
34940 KB |
Output is correct |
24 |
Correct |
596 ms |
39628 KB |
Output is correct |
25 |
Correct |
596 ms |
39632 KB |
Output is correct |