108702024-04-17 09:23:0142Évzárópython3Accepted 100/100792ms116468 KiB
# discrepancy, balanced 2-coloring, IMO6 1986

from sys import stdin, stdout
input=stdin.readline

def f(x,y):
    return 10**9*x+y

#def g(c):
#    return c//10**9,c%10**9

def main():
    N = int(input())
    d={}
    hor={}
    ver={}
    graph={}
    for i in range(N):
        x,y = list(map(int, input().split()))
        d[f(x,y)] = i
        try:
            xx=hor.pop(y)
            try: graph[f(x,y)].append(f(xx,y))
            except: graph[f(x,y)] = [f(xx,y)]
            try: graph[f(xx,y)].append(f(x,y))
            except: graph[f(xx,y)] = [f(x,y)]
        except: hor[y]=x
        try:
            yy=ver.pop(x)
            try: graph[f(x,y)].append(f(x,yy))
            except: graph[f(x,y)] = [f(x,yy)]
            try: graph[f(x,yy)].append(f(x,y))
            except: graph[f(x,yy)] = [f(x,y)]
        except: ver[x]=y
    res=[True]*N
    while graph:
        v,cur=graph.popitem()
        l=1
        res[d[v]]=False
        while cur:
            if l%2==0:
                for v in cur:
                    res[d[v]]=False
            tmp=[]
            for v in cur:
                if v in graph:
                    sz=graph.pop(v)
                    for w in sz:
                        if w in graph:
                            tmp.append(w)
            cur=tmp
            l+=1
    for x in res:
        if x:
            stdout.write('L')
        else:
            stdout.write('F')
    stdout.write('\n')
        
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11828 KiB
2Accepted740ms103944 KiB
subtask25/5
3Accepted505ms107428 KiB
4Accepted551ms107552 KiB
subtask37/7
5Accepted505ms107428 KiB
6Accepted551ms107552 KiB
7Accepted552ms107752 KiB
8Accepted564ms107712 KiB
9Accepted555ms106320 KiB
10Accepted317ms73328 KiB
subtask420/20
11Accepted787ms112576 KiB
12Accepted792ms112856 KiB
13Accepted791ms113120 KiB
14Accepted792ms113028 KiB
15Accepted768ms116468 KiB
16Accepted314ms74248 KiB
subtask513/13
17Accepted18ms13636 KiB
18Accepted18ms13544 KiB
19Accepted17ms13376 KiB
20Accepted18ms13596 KiB
21Accepted18ms13808 KiB
22Accepted18ms13560 KiB
23Accepted18ms13772 KiB
24Accepted18ms13748 KiB
25Accepted18ms13756 KiB
26Accepted17ms13356 KiB
27Accepted17ms13620 KiB
28Accepted18ms13776 KiB
29Accepted17ms14036 KiB
30Accepted17ms14272 KiB
31Accepted18ms14320 KiB
32Accepted18ms14220 KiB
33Accepted17ms14572 KiB
subtask620/20
34Accepted18ms13636 KiB
35Accepted18ms13544 KiB
36Accepted17ms13376 KiB
37Accepted18ms13596 KiB
38Accepted18ms13808 KiB
39Accepted18ms13560 KiB
40Accepted18ms13772 KiB
41Accepted18ms13748 KiB
42Accepted18ms13756 KiB
43Accepted17ms13356 KiB
44Accepted17ms13620 KiB
45Accepted18ms13776 KiB
46Accepted17ms14036 KiB
47Accepted17ms14272 KiB
48Accepted18ms14320 KiB
49Accepted18ms14220 KiB
50Accepted17ms14572 KiB
51Accepted24ms15624 KiB
52Accepted23ms15368 KiB
53Accepted24ms15692 KiB
54Accepted24ms15688 KiB
55Accepted24ms15728 KiB
56Accepted24ms15896 KiB
57Accepted24ms15824 KiB
58Accepted24ms15788 KiB
59Accepted24ms15944 KiB
60Accepted24ms15784 KiB
61Accepted24ms15636 KiB
62Accepted24ms15516 KiB
63Accepted24ms15652 KiB
64Accepted23ms15608 KiB
65Accepted24ms15956 KiB
subtask735/35
66Accepted18ms13636 KiB
67Accepted740ms106724 KiB
68Accepted505ms107428 KiB
69Accepted551ms107552 KiB
70Accepted552ms107752 KiB
71Accepted564ms107712 KiB
72Accepted555ms106320 KiB
73Accepted317ms73328 KiB
74Accepted787ms112576 KiB
75Accepted792ms112856 KiB
76Accepted791ms113120 KiB
77Accepted792ms113028 KiB
78Accepted768ms116468 KiB
79Accepted314ms74248 KiB
80Accepted18ms13544 KiB
81Accepted17ms13376 KiB
82Accepted18ms13596 KiB
83Accepted18ms13808 KiB
84Accepted18ms13560 KiB
85Accepted18ms13772 KiB
86Accepted18ms13748 KiB
87Accepted18ms13756 KiB
88Accepted17ms13356 KiB
89Accepted17ms13620 KiB
90Accepted18ms13776 KiB
91Accepted17ms14036 KiB
92Accepted17ms14272 KiB
93Accepted18ms14320 KiB
94Accepted18ms14220 KiB
95Accepted17ms14572 KiB
96Accepted24ms15624 KiB
97Accepted23ms15368 KiB
98Accepted24ms15692 KiB
99Accepted24ms15688 KiB
100Accepted24ms15728 KiB
101Accepted24ms15896 KiB
102Accepted24ms15824 KiB
103Accepted24ms15788 KiB
104Accepted24ms15944 KiB
105Accepted24ms15784 KiB
106Accepted24ms15636 KiB
107Accepted24ms15516 KiB
108Accepted24ms15652 KiB
109Accepted23ms15608 KiB
110Accepted24ms15956 KiB
111Accepted707ms106252 KiB
112Accepted684ms103560 KiB
113Accepted685ms103116 KiB
114Accepted712ms106220 KiB
115Accepted735ms106108 KiB
116Accepted660ms105900 KiB
117Accepted661ms106400 KiB
118Accepted661ms106188 KiB
119Accepted734ms105960 KiB
120Accepted736ms106788 KiB
121Accepted657ms106356 KiB