mfake = 0 for x in range(1 << N): Ff, Sf = [], [] Fr, Sr = [], [] for i in range(N): if (x >> i) & 1: Fr.append(F[i]) Sr.append(S[i]) else: Ff.append(F[i]) Sf.append(S[i]) #print(Ff, Sf, ':', Fr, Sr) Nr = len(Fr) Nf = len(Ff) fake = 0 for i in range(Nf): ffake = Ff[i] in Fr sfake = Sf[i] in Sr #print(ffake, sfake) if ffake and sfake: fake += 1 mfake = max(fake, mfake) gcj.print_answer(ofile, t, mfake)
ifile, ofile = gcj.get_files('A') T = int(ifile.readline().strip()) for t in range(T): fields = ifile.readline().split() P = fields[0] N = len(P) K = int(fields[1]) x = 0 B = [0] * N for p in P: x *= 2 if p == '-': x += 1 for i in range(N): if P[i] == '+': B[i] = 1 #print(P,"->",x) #ans = dfs(x, N, K) ans = linear(B, N, K) #if attempt != ans: # print("ALARMA", P, attempt, ans) if ans == -1: ans = "IMPOSSIBLE" else: ans = str(ans) gcj.print_answer(ofile, t, ans)
sixes = b[13] for i in range(N): b[i] -= sixes * A[6][i] #print(eights, b) eights = b[1] for i in range(N): b[i] -= eights * A[8][i] ones = b[5] for i in range(N): b[i] -= ones * A[1][i] threes = b[4] for i in range(N): b[i] -= threes * A[3][i] fives = b[2] for i in range(N): b[i] -= fives * A[5][i] sevens = b[7] for i in range(N): b[i] -= sevens * A[7][i] #print(b) nines = b[0] gcj.print_answer(ofile, t, ("0" * zeroes) + ("1" * ones) + "2" * twoes + "3" * threes + "4" * fours + "5" * fives + "6" * sixes + "7" * sevens + "8" * eights + "9" * nines)
mn = pow(10, len(CJ)) Cm = pow(10, len(CJ)) ans = '' L = len(CJ) #print(mn, Cm) for m in itertools.product([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], repeat=missed): CJn = CJ mi = 0 for i in range(len(CJn)): if CJn[i] == '?': CJn = CJn[:i] + str(m[mi]) + CJn[i + 1:] mi += 1 Cn = int(CJn[:L // 2]) Jn = int(CJn[L // 2:]) #print(CJn) if abs(Cn - Jn) < mn: mn = abs(Cn - Jn) Cm = Cn Jm = Jn ans = CJn if abs(Cn - Jn) == mn and Cn < Cm: mn = abs(Cn - Jn) Cm = Cn Jm = Jn ans = CJn gcj.print_answer(ofile, t, ans[:L // 2] + ' ' + ans[L // 2:])
(len(SN) - first_tidy - 1)) def tidy(N): SN = str(N) for i in range(len(SN) - 1): if SN[i] > SN[i + 1]: return False return True def brute(N): last = 0 for i in range(1, N + 1): if tidy(i): last = i return last ifile, ofile = gcj.get_files('B') T = int(ifile.readline().strip()) for t in range(T): N = int(ifile.readline()) #N = random.randint(1, 100000) #ans = brute(N) #if brute(N) != last_tidy(N): # print("ALARMA", N, brute(N), last_tidy(N)) ans = last_tidy(N) gcj.print_answer(ofile, t, str(ans))
S = sum(P) if S > 0 and max(P) > S // 2: P[ix2] += 1 return chr(ord('A') + ix1) return "" + chr(ord('A') + ix1) + chr(ord('A') + ix2) ifile, ofile = gcj.get_files('A') T = int(ifile.readline().strip()) for t in range(T): N = int(ifile.readline().strip()) P = list(map(int, ifile.readline().strip().split(" "))) ans = [] #print(P) while True: S = sum(P) if S > 0: a = to_exit(P) #print(P, a) ans.append("" + a) else: break gcj.print_answer(ofile, t, ' '.join(ans))
#gcj.set_sample() ifile, ofile = gcj.get_files('A') T = int(ifile.readline().strip()) for t in range(T): #sorted(range(len(s)), key=lambda k: s[k]) (N, K) = list(map(int, ifile.readline().split())) R, H = [], [] for n in range(N): (r, h) = list(map(int, ifile.readline().split())) R.append(r) H.append(h) rindices = sorted(range(len(R)), key=lambda k: R[k], reverse=True) #print(rindices) area = 0 for ri in range(N - K + 1): start_r = rindices[ri] #print("start_ri", start_r) rh = [H[rindices[i]] * R[rindices[i]] for i in range(ri + 1, N)] #print(rh) srh = sorted(rh, reverse=True) #print(srh, R[start_r]) a = math.pi * (2 * (sum(srh[0:(K - 1)]) + H[start_r]*R[start_r])+ R[start_r] * R[start_r]) #print(a) area = max(area, a) gcj.print_answer(ofile, t, area)