diff options
Diffstat (limited to '2011/qual/b/b.py')
| -rw-r--r-- | 2011/qual/b/b.py | 39 |
1 files changed, 35 insertions, 4 deletions
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 |
