summaryrefslogtreecommitdiff
path: root/2011/qual/a/a.py
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2011-05-07 02:43:12 +0300
committerYuval Adam <yuv.adm@gmail.com>2011-05-07 02:43:12 +0300
commit76aa2308ea962f204475409ee8f6f17055e6f719 (patch)
tree6d8361226b94fc3bd3a95a09efd670b3445d9027 /2011/qual/a/a.py
parentd057970c6a7096ea6ffb04beb0f97ca3ddf19f3e (diff)
finished a
Diffstat (limited to '2011/qual/a/a.py')
-rw-r--r--2011/qual/a/a.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/2011/qual/a/a.py b/2011/qual/a/a.py
index f3841a7..9f574da 100644
--- a/2011/qual/a/a.py
+++ b/2011/qual/a/a.py
@@ -1,12 +1,43 @@
-f = open('1.in', 'r')
-o = open('1.out', 'w')
+f = open('3.in', 'r')
+o = open('3.out', 'w')
T = int(f.readline().strip())
for t in xrange(T):
- (n, k) = map(int, f.readline().strip().split(' '))
+ line = f.readline().strip().split(' ')[1:]
+ prs = zip(line[::2], map(int,line[1::2]))
- s = "Case #%d: %s\n" % (t+1, res)
+ oprs = [x[1] for x in prs if x[0]=='O']
+ bprs = [x[1] for x in prs if x[0]=='B']
+
+ op, bp = 1, 1
+
+ step = 0
+ while (prs):
+ step += 1
+ #print prs, oprs, bprs, op, bp
+ pushed = False
+ if oprs:
+ if prs[0] == ('O', op):
+ oprs = oprs[1:]
+ prs = prs[1:]
+ pushed = True
+ elif oprs[0] > op:
+ op += 1
+ elif oprs[0] < op:
+ op -= 1
+
+ if bprs:
+ if prs[0] == ('B', bp) and not pushed:
+ bprs = bprs[1:]
+ prs = prs[1:]
+ elif bprs[0] > bp:
+ bp += 1
+ elif bprs[0] < bp:
+ bp -= 1
+
+ res = step
+ s = "Case #%d: %d\n" % (t+1, res)
#print s
o.write(s)