From 6f4006e49a11c7e409a951de93296f2c2a1890c4 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Thu, 18 Apr 2019 10:04:24 +0200 Subject: [PATCH] Added wrong solution to J --- circular_dna.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++++ circular_dna.txt | 2 + 2 files changed, 97 insertions(+) create mode 100644 circular_dna.py create mode 100644 circular_dna.txt diff --git a/circular_dna.py b/circular_dna.py new file mode 100644 index 0000000..86b2c57 --- /dev/null +++ b/circular_dna.py @@ -0,0 +1,95 @@ +#!/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 + 1) + + 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, 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)) + + diff --git a/circular_dna.txt b/circular_dna.txt new file mode 100644 index 0000000..1a484fc --- /dev/null +++ b/circular_dna.txt @@ -0,0 +1,2 @@ +9 +e1 e1 s1 e2 s1 s2 e42 e1 s1