From 56a19725f7a66a94b85c10d85b73d25ec47ffabe Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sat, 7 May 2011 04:55:32 +0300 Subject: b almost working, d still investigating --- 2011/qual/b/b.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to '2011/qual/b/b.py') diff --git a/2011/qual/b/b.py b/2011/qual/b/b.py index f9f028a..4beebd9 100644 --- a/2011/qual/b/b.py +++ b/2011/qual/b/b.py @@ -1,13 +1,44 @@ -f = open('1.in', 'r') -o = open('1.out', 'w') +f = open('2.in', 'r') +o = open('2.out', 'w') T = int(f.readline().strip()) for t in xrange(T): - _n = f.readline().strip().split(' ') - el = map(int, f.readline().strip().split(' ')) + line = f.readline().strip().split(' ') + C = int(line[0]) + comb = line[1:1+C] + D = int(line[C+1]) + opp = line[C+2:C+2+D] + s = [x for x in line[-1]] + cd = dict([(x[0:2], x[2]) for x in comb]) + od = opp + + el = [] + print cd, od, s + for c in s: + print el + + if not el: + el.append(c) + continue + + last = el[-1] + lc = last + c + cl = c + last + + if cd.get(lc): + el.pop() + el.append(cd.get(lc)) + elif cd.get(cl): + el.pop() + el.append(cd.get(cl)) + elif any([c + e in od or e + c in od for e in el]): + el = [] + else: + el.append(c) + res = el s = "Case #%d: %s\n" % (t+1, res) print s -- cgit v1.3.1