Submission #11556

# Submission time Handle Problem Language Result Execution time Memory
11556 2014-12-01T09:53:42 Z gs12117 전선 연결하기 (GA9_wire) C++
100 / 100
312 ms 27508 KB
#include<stdio.h>
int n;
int a[600100];
int b[300100][2];
int chk[300100];
int uft[300100][2];
int it[1<<21];
int itm[1<<21];
int flag;
int uftf(int x){
    if(uft[x][0]==x)return x;
    uftf(uft[x][0]);
    uft[x][1]^=uft[uft[x][0]][1];
    return uft[x][0]=uft[uft[x][0]][0];
}
void push(int loc,int val){
    loc+=1<<20;
    itm[loc]=1;
    while(loc!=0){
        it[loc]=val;
        loc/=2;
    }
}
void pop(int loc){
    loc+=1<<20;
    it[loc]=0;
    loc/=2;
    while(loc!=0){
        if(it[loc*2]!=0)it[loc]=it[loc*2];
        else it[loc]=it[loc*2+1];
        loc/=2;
    }
}
void link(int pa,int pb,int val){
    if(uftf(pa)==uftf(pb)){
        if((uft[pa][1]^uft[pb][1])!=val)flag=1;
    }
    else{
        uft[uft[pb][0]][1]=(val^uft[pa][1]^uft[pb][1]);
        uft[uft[pb][0]][0]=uft[pa][0];
    }
}
void merge(int loc){
    if(it[loc]==0||itm[loc]==1)return;
    merge(loc*2);
    merge(loc*2+1);
    itm[loc]=1;
    if(it[loc*2]!=0&&it[loc*2+1]!=0){
        link(it[loc*2],it[loc*2+1],0);
    }
}
void calc(int start,int end,int p){
    start+=1<<20;
    end+=1<<20;
    while(start<=end){
        if(start%2==1){
            merge(start);
            if(it[start]!=0)link(p,it[start],1);
            start++;
        }
        if(end%2==0){
            merge(end);
            if(it[end]!=0)link(p,it[end],1);
            end--;
        }
        start/=2;
        end/=2;
    }
}
int main(){
    int i;
    scanf("%d",&n);
    for(i=0;i<2*n;i++){
        scanf("%d",&a[i]);
        b[a[i]][chk[a[i]]]=i;
        chk[a[i]]++;
    }
    for(i=1;i<=n;i++){
        uft[i][0]=i;
        uft[i][1]=0;
    }
    for(i=1;i<=n;i++){
        push(b[i][0],i);
    }
    flag=0;
    for(i=0;i<2*n;i++){
        if(b[a[i]][1]==i){
            pop(b[a[i]][0]);
            calc(b[a[i]][0],b[a[i]][1],a[i]);
        }
    }
    if(flag==1){
        printf("IMPOSSIBLE");
    }
    else{
        for(i=1;i<=n;i++){
            uftf(i);
        }
        for(i=0;i<2*n;i++){
            if(uft[a[i]][1]==0)printf("^");
            else printf("v");
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25676 KB Output is correct
2 Correct 0 ms 25676 KB Output is correct
3 Correct 0 ms 25676 KB Output is correct
4 Correct 0 ms 25676 KB Output is correct
5 Correct 0 ms 25676 KB Output is correct
6 Correct 0 ms 25676 KB Output is correct
7 Correct 0 ms 25676 KB Output is correct
8 Correct 0 ms 25676 KB Output is correct
9 Correct 0 ms 25676 KB Output is correct
10 Correct 0 ms 25676 KB Output is correct
11 Correct 0 ms 25676 KB Output is correct
12 Correct 0 ms 25676 KB Output is correct
13 Correct 0 ms 25676 KB Output is correct
14 Correct 0 ms 25676 KB Output is correct
15 Correct 0 ms 25676 KB Output is correct
16 Correct 0 ms 25676 KB Output is correct
17 Correct 0 ms 25676 KB Output is correct
18 Correct 0 ms 25676 KB Output is correct
19 Correct 0 ms 25676 KB Output is correct
20 Correct 0 ms 25676 KB Output is correct
21 Correct 0 ms 25676 KB Output is correct
22 Correct 0 ms 25676 KB Output is correct
23 Correct 0 ms 25676 KB Output is correct
24 Correct 0 ms 25676 KB Output is correct
25 Correct 0 ms 25676 KB Output is correct
26 Correct 0 ms 25676 KB Output is correct
27 Correct 0 ms 25676 KB Output is correct
28 Correct 0 ms 25676 KB Output is correct
29 Correct 0 ms 25676 KB Output is correct
30 Correct 0 ms 25676 KB Output is correct
31 Correct 0 ms 25676 KB Output is correct
32 Correct 0 ms 25676 KB Output is correct
33 Correct 0 ms 25676 KB Output is correct
34 Correct 0 ms 25676 KB Output is correct
35 Correct 0 ms 25676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 25676 KB Output is correct
2 Correct 0 ms 25676 KB Output is correct
3 Correct 0 ms 25676 KB Output is correct
4 Correct 0 ms 25676 KB Output is correct
5 Correct 0 ms 25676 KB Output is correct
6 Correct 0 ms 25676 KB Output is correct
7 Correct 0 ms 25676 KB Output is correct
8 Correct 0 ms 25676 KB Output is correct
9 Correct 0 ms 25676 KB Output is correct
10 Correct 0 ms 25676 KB Output is correct
11 Correct 0 ms 25676 KB Output is correct
12 Correct 0 ms 25676 KB Output is correct
13 Correct 0 ms 25676 KB Output is correct
14 Correct 0 ms 25676 KB Output is correct
15 Correct 0 ms 25676 KB Output is correct
16 Correct 0 ms 25676 KB Output is correct
17 Correct 0 ms 25676 KB Output is correct
18 Correct 0 ms 25676 KB Output is correct
19 Correct 0 ms 25676 KB Output is correct
20 Correct 0 ms 25676 KB Output is correct
21 Correct 0 ms 25676 KB Output is correct
22 Correct 0 ms 25676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 25676 KB Output is correct
2 Correct 8 ms 25676 KB Output is correct
3 Correct 60 ms 25676 KB Output is correct
4 Correct 60 ms 25676 KB Output is correct
5 Correct 44 ms 25676 KB Output is correct
6 Correct 32 ms 25676 KB Output is correct
7 Correct 56 ms 25676 KB Output is correct
8 Correct 4 ms 25676 KB Output is correct
9 Correct 8 ms 25676 KB Output is correct
10 Correct 44 ms 25676 KB Output is correct
11 Correct 40 ms 25676 KB Output is correct
12 Correct 36 ms 25676 KB Output is correct
13 Correct 36 ms 25676 KB Output is correct
14 Correct 44 ms 25676 KB Output is correct
15 Correct 64 ms 25676 KB Output is correct
16 Correct 8 ms 25676 KB Output is correct
17 Correct 16 ms 25676 KB Output is correct
18 Correct 68 ms 25676 KB Output is correct
19 Correct 44 ms 25676 KB Output is correct
20 Correct 64 ms 25676 KB Output is correct
21 Correct 48 ms 25676 KB Output is correct
22 Correct 52 ms 25676 KB Output is correct
23 Correct 72 ms 25676 KB Output is correct
24 Correct 76 ms 25676 KB Output is correct
25 Correct 68 ms 25676 KB Output is correct
26 Correct 52 ms 25676 KB Output is correct
27 Correct 72 ms 26072 KB Output is correct
28 Correct 92 ms 26072 KB Output is correct
29 Correct 80 ms 26176 KB Output is correct
30 Correct 72 ms 26260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 25676 KB Output is correct
2 Correct 164 ms 25676 KB Output is correct
3 Correct 112 ms 25676 KB Output is correct
4 Correct 148 ms 25676 KB Output is correct
5 Correct 200 ms 25676 KB Output is correct
6 Correct 240 ms 25676 KB Output is correct
7 Correct 260 ms 25676 KB Output is correct
8 Correct 188 ms 25676 KB Output is correct
9 Correct 136 ms 25676 KB Output is correct
10 Correct 124 ms 25676 KB Output is correct
11 Correct 160 ms 25676 KB Output is correct
12 Correct 128 ms 25676 KB Output is correct
13 Correct 252 ms 25676 KB Output is correct
14 Correct 212 ms 25676 KB Output is correct
15 Correct 124 ms 25676 KB Output is correct
16 Correct 124 ms 25676 KB Output is correct
17 Correct 124 ms 25676 KB Output is correct
18 Correct 120 ms 25676 KB Output is correct
19 Correct 192 ms 25676 KB Output is correct
20 Correct 260 ms 25676 KB Output is correct
21 Correct 240 ms 25676 KB Output is correct
22 Correct 312 ms 27112 KB Output is correct
23 Correct 308 ms 27116 KB Output is correct
24 Correct 292 ms 27508 KB Output is correct
25 Correct 284 ms 27168 KB Output is correct