From 76aa2308ea962f204475409ee8f6f17055e6f719 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Sat, 7 May 2011 02:43:12 +0300 Subject: finished a --- 2011/qual/a/a.py | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to '2011/qual/a/a.py') 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) -- cgit v1.3.1