97 lines
1.9 KiB
Python
Executable file
97 lines
1.9 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
class Gene:
|
|
def __init__(self, s):
|
|
self.isStart = s[0] == 's'
|
|
self.n = int(s[1:])
|
|
|
|
def __str__(self):
|
|
if self.isStart:
|
|
return "<" + str(self.n)
|
|
else:
|
|
return str(self.n) + ">"
|
|
|
|
def __repr__(self):
|
|
return self.__str__()
|
|
|
|
def is_start_end(g, h):
|
|
return g.isStart and not h.isStart and g.n == h.n
|
|
|
|
def overlaps(a, b):
|
|
return a[start]
|
|
|
|
def count_genes(G):
|
|
C = {}
|
|
mC = {}
|
|
FS = {}
|
|
S = {}
|
|
E = {}
|
|
for i in range(len(G)):
|
|
e = G[i].n
|
|
if not e in C:
|
|
C[e] = 0
|
|
mC[e] = 0
|
|
S[e] = i if G[i].isStart else None
|
|
E[e] = None
|
|
FS[e] = False
|
|
|
|
if G[i].isStart:
|
|
C[e] += 1
|
|
|
|
if FS[e]:
|
|
FS[e] = False
|
|
S[e] = i
|
|
else:
|
|
C[e] -= 1
|
|
|
|
if C[e] < mC[e]:
|
|
mC[e] = C[e]
|
|
E[e] = i
|
|
FS[e] = True
|
|
|
|
|
|
i = 0
|
|
print(C)
|
|
print(S, E)
|
|
|
|
I = []
|
|
CI = [0]
|
|
for key in C:
|
|
if C[key] == 0:
|
|
I.append((S[key], +1))
|
|
I.append((E[key], -1))
|
|
if I[0][0] >= S[key] or I[0][0] <= E[key]:
|
|
CI[0] += 1
|
|
|
|
if len(I) == 0:
|
|
return (0, 0)
|
|
|
|
last = CI[0]
|
|
for i in range(1, len(I)):
|
|
if I[i][1] == +1:
|
|
last = last + 1
|
|
CI.append(last)
|
|
else:
|
|
last = last - 1
|
|
CI.append(last)
|
|
|
|
print(CI)
|
|
|
|
m = CI[0]
|
|
p = I[0][0]
|
|
for i in range(len(CI)):
|
|
if CI[i] > m:
|
|
m = CI[i]
|
|
p = I[i][0]
|
|
|
|
return (p + 1, m)
|
|
|
|
if __name__ == "__main__":
|
|
n = int(input())
|
|
genes = input().split()
|
|
for i in range(len(genes)):
|
|
genes[i] = Gene(genes[i])
|
|
start, number = count_genes(genes)
|
|
print(str(start) + " " + str(number))
|
|
|
|
|