summaryrefslogtreecommitdiff
path: root/2011/qual/b/b.py
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2011-05-07 04:55:32 +0300
committerYuval Adam <yuv.adm@gmail.com>2011-05-07 04:55:32 +0300
commit56a19725f7a66a94b85c10d85b73d25ec47ffabe (patch)
treee56ef6860dbda8bf414a83874c7f3b2d8238c6bc /2011/qual/b/b.py
parent40d6a93d9065e45f18c217e281936eff57ba37d6 (diff)
b almost working, d still investigating
Diffstat (limited to '2011/qual/b/b.py')
-rw-r--r--2011/qual/b/b.py39
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