def solve(N, ss): f = 0 c = 0 for i, s in enumerate(ss): if c < i: f += i - c c += i - c
c += s
return f, c
for i in range(T): N, S = fin.readline().split() ss = [] for j in range(int(N)+1): ss.append(int(S[j])) solution = solve(int(N), ss) answer = "Case #%d: %s\n" % (i+1, solution[0]) print answer fout.write(answer)
def mult(qs): r = q('1') for vq in qs: r = r * vq return r
def mult_table(table, vs, a, b, indices): key = str(a) + ',' + str(b) if table.has_key(key): return table[key] else: cs = [x for x in indices if a < x < b] if not cs: value = mult(vs[a:b]) else: c = cs[len(cs)/2] value = mult_table(table, vs, a, c, indices) * mult_table(table, vs, c, b, indices) #print key, value, a, c, b table[key] = value return value
#print q('i') * q('j'), q('j') * q('k'), q('i') * q('j') * q('k') def solve(L, X, ijk): fqs = [] for i in ijk: if i == 'i' or i == 'j' or i == 'k': fqs.append(q(i)) qs = [] X = X % 16 extend = min(X, 4) for i in range(extend): qs.extend(fqs)
print qs lq = q('1') left_plus = [] left_minus = [] for i_l, l in enumerate(qs): # print lq, l lq = nx = lq * l if nx == q('i'): left_plus = [i_l+1, nx, l] if nx == -q('i'): left_minus = [i_l+1, nx, l] if left_plus and left_minus: break right_plus = [] right_minus = [] rq = q('1') for i_r, r in enumerate(reversed(qs)): rq = nx = r * rq if nx == q('k'): right_plus = [i_r+1, nx, r] elif nx == -q('k'): right_minus = [i_r+1, nx, r] if right_plus and right_minus: break if (not left_plus) and not left_minus: return "NO" if not right_plus and not right_minus: return "NO" dqs = [] for idqs in range(X):#range(min(X, 8)): dqs.extend(fqs)
lefts = [] rights = []
mc = {} mfqs = mult(fqs) indices = [] if left_plus: indices.append(left_plus[0]) lefts.append(left_plus) if left_minus: indices.append(left_minus[0]) lefts.append(left_minus) if right_plus: indices.append(len(dqs) - right_plus[0]) rights.append(right_plus) if right_minus: indices.append(len(dqs) - right_minus[0]) rights.append(right_minus) for ie in range(8): index = ie * len(fqs) indices.append(index) mc[str(index) + ',' + str(index + len(fqs))] = mfqs sorted_indices = sorted(set(indices))
# prev = -1 # mc = mult_table(qs, sorted_indices) # for ii in sorted_indices: # for ij in sorted_indices[]: # if # if prev > 0 # mc[[prev, index]] = mult(qs[prev:index+1]) # prev = index print mfqs, mc, sorted_indices for j_l in lefts: for j_r in rights: if j_l[0] + j_r[0] < len(dqs) + 2: #isj = mult_table(mc, dqs, j_l[0], len(dqs)-j_r[0], sorted_indices) isj = mult(dqs[j_l[0] : len(dqs) - j_r[0] ]) #print j_l[1], isj, j_r[1], j_l[1] * isj * j_r[1] if j_l[1] * isj * j_r[1] == -q('1'): return "YES" # else: # j_left = mult(dqs[j_l[0] : -1]) # j_right = mult(dqs[0 : len(dqs) - j_r[0]]) # j_middle = q('1') # for k_d in range(min(X - 8, 4)): # j_middle = j_middle * mfqs # if j_l[1] * j_left * j_middle * j_right * j_r[1] == -q('1'): # return "YES" return "NO" for i in range(T): L, X = map(int, fin.readline().split()) ijk = fin.readline() solution = solve(L, X, ijk) # if solution > candidate: # print 'ERROR', i + 1, solution, candidate # if solution != solution1: # print 'ERROR', i + 1, solution, solution1, candidate answer = "Case #%d: %s\n" % (i + 1, solution) print answer fout.write(answer)
Gabriel = "GABRIEL" Richard = "RICHARD" def solve(X, R, C): if (R * C) % X != 0: print "%" return Richard if R < X and C < X: print "<" return Richard if X > 6: print "6" return Richard min_l = 1 + (X - 1) / 2 if X > 2 and (R < min_l or C < min_l): print "sqrt" return Richard snake = 2 + (X - 2) / 3 if X > 3 and (R <= snake or C <= snake): print "snake" if X == 4: return Richard elif X == 5 and (R < 5 and C < 5): return Richard elif X == 6 and (R < 7 and C < 7): return Richard
return Gabriel
for i in range(T): X, R, C = map(int, fin.readline().split()) print i+1, X, R, C
solution = solve(X, R, C) # if solution > candidate: # print 'ERROR', i + 1, solution, candidate # if solution != solution1: # print 'ERROR', i + 1, solution, solution1, candidate answer = "Case #%d: %s\n" % (i + 1, solution) print answer fout.write(answer)
def solve(outlets, plugs, N, L): #print outlets, plugs plugs.sort()
shuffle = [] switch = [] unknown = [] for i in range(L): ips = [(p >> i) % 2 for p in plugs] ios = [(o >> i) % 2 for o in outlets] print i, ips, ios if ips.count(1) == ios.count(1): if ips.count(1) == ips.count(0): unknown.append(i) elif ips.count(0) == ios.count(1): if ips.count(1) == ips.count(0): unknown.append(i) else: shuffle.append(i) else: return "NOT POSSIBLE" shuffled_outlets = outlets[:] for s in shuffle: shuffled_outlets = [o ^ pow(2, s) for o in shuffled_outlets]
result = len(shuffle) print plugs print shuffled_outlets
if plugs == shuffled_outlets: return str(result)
for i in range(len(unknown)): for j in itertools.combinations(unknown, i+1): shuffled_outlets2 = shuffled_outlets[:] for k in j: shuffled_outlets2 = [o ^ pow(2, k) for o in shuffled_outlets2] shuffled_outlets2.sort() #print shuffled_outlets if plugs == shuffled_outlets2: return str(result + i + 1)
return "NOT POSSIBLE" for i in range(T): N, L = map(int, fin.readline().split()) outlets = [int(n, 2) for n in (fin.readline().split())] plugs = [int(n, 2) for n in (fin.readline().split())] print 'o', outlets print 'p', plugs solution = solve(outlets, plugs, N, L) if N == 1 and solution == "NOT POSSIBLE": print "ERROR1" if solution != "NOT POSSIBLE" and N < int(solution): print "ERROR2" answer = "Case #%d: %s\n" % (i+1, solution) print answer fout.write(answer)
#sorted_star2_indices = [v[0] for v in sorted(enumerate(star2s), key=lambda x:x[1])] sorted_star2_indices = [v[0] for v in sorted(enumerate(star2s), cmp=greater)] sorted_star2_values = [v[1] for v in sorted(enumerate(star2s), cmp=greater)]
for i in range(T): N = int(fin.readline()) stars = [] completed = [] for j in range(N): stars.append(map(int, fin.readline().split())) completed.append(False)
#sys.stdout = open(os.devnull, 'w') T = int(fin.readline())
def bribe(rs, s, e): if not rs: return 0 if s >= e: return 0 center = (s + e) / 2.0 closest = e + 2 for i in rs: if abs(center - i) < abs(center - closest): closest = i
left = [a for a in rs if a < closest] right = [a for a in rs if a > closest] print s, e, closest, e - s, left, right return (e - s) + bribe(left, s, closest - 1) + bribe(right, closest + 1, e)
solutions = {} def dynamic_bribe(rs, s, e, space): if not rs: return "", 0 if s >= e: return '', 0 s0 = 1 e0 = e - s + 1 rs0 = [a - s + 1 for a in rs]
key = str(e0) + ':' + (',').join(str(a) for a in rs0) keystr = str(s) + '~' + str(e) + ':' + (',').join(str(a) for a in rs) solution = solutions.get(key) if solution: #print space, s, e, rs, solution, "key:" + key #return '\n' + space + '<' + keystr + '_' + str(solution) + '>\n', solution return '', solution else: candidate = sys.maxint way = "" for r in rs: left = [a for a in rs if a < r] right = [a for a in rs if a > r] left_way, lc = dynamic_bribe(left, s, r-1, space + ' ') right_way, rc = dynamic_bribe(right, r+1, e, space + ' ') cc = (e - s) + lc + rc if cc < candidate: candidate = cc way = '\n' + space + '<' + keystr + '_' + str(cc) + ',' + left_way + ',' + right_way + '>\n' solution = candidate solutions[key] = solution #print space, s, e, rs, solution #return way, solution return '', solution
#print dynamic_bribe([3], 1, 8, '') def solve(P, Q, rs): a = bribe(rs, 1, P) #print '' #if a != b: # print "DIFFERENT", a, b, a > b return a
def dynamic_solve(P, Q, rs): way, b = dynamic_bribe(rs, 1, P, '') print way return b
cases = [15]
for i in range(T): #if i > 3: # break solutions = {} P, Q = map(int, fin.readline().split()) rsline = fin.readline() rs = map(int, rsline.split())
#if i in cases: if True: print P, Q, rs #answer = solve(P, Q, rs) #line = "Case #%d: %s" % (i+1, str(answer)) #print line + '; ' + rsline + '\n' #f1out.write(line + '\n') answer2 = dynamic_solve(P, Q, rs) line2 = "Case #%d: %s" % (i+1, str(answer2)) print line2 + '; ' + rsline + '\n' fout.write(line2 + '\n')
Qualification Round. Code Jam will start with a qualification round on Friday, April 10, 2015 at 23:00 UTC (4:00 PM PT) and run for 27 hours, ending on Sunday, April 12, 2015 at 2:00 UTC (Saturday, April 11, 2015 at 7:00pm PT). In the Qualification Round, you must log in to the Contest website to attempt to solve a number of problems within the 27-hour period. If you earn a minimum number of points during the qualification round, which will be displayed on the Contest website, you will advance to Round 1 of Code Jam.
QR은 절대평가. 쉽다고 한다.
Round 1. Code Jam Round 1 is conducted online and is offered in three sub-rounds at the times specified at https://code.google.com/codejam/schedule.html from Saturday, April 18, 2015 (Friday, April 17th PST) to Sunday, May 10, 2015. If you advanced to Code Jam Round 1, you can participate in any or all of the sub-rounds by logging into the Contest website to solve a number of problems until you qualify for Code Jam Round 2. However, once you qualify for Code Jam Round 2, you may not participate in any later sub-rounds of Code Jam Round 1. You will advance to Code Jam Round 2 if you are one of the top-scoring 1000 contestants from one of the sub-rounds in Code Jam Round 1. You will be notified by email after the end of each sub-round if you are one of the 3000 contestants advancing to Code Jam Round 2.
If you advanced to Code Jam Round 1, you can participate in any or all of the sub-rounds by logging into the Contest website to solve a number of problems until you qualify for Code Jam Round 2. However, once you qualify for Code Jam Round 2, you may not participate in any later sub-rounds of Code Jam Round 1.
RECENT COMMENT