input
stringlengths
20
127k
target
stringlengths
20
119k
problem_id
stringlengths
6
6
X, K, D = [int(a) for a in list(input().split())] X = abs(X) for i in range(X//D): X -= D K -= 1 if K == 0: print((abs(X))) exit() if K % 2 == 0: print(X) else: print((abs(X-D)))
X, K, D = [int(a) for a in list(input().split())] X = abs(X) q = X//D r = X%D if q >= K: print((X - D*K)) exit() rem = K - q if rem % 2 == 0: print(r) else: print((abs(D-r)))
p02584
X, K, D = list(map(int, input().split())) for i in range(K): if (abs(X) > D): X = abs(X) - D else: if ((K - i) % 2 == 0): break else: X = X - D break print((abs(X)))
X, K, D = list(map(int, input().split())) syou = abs(X) // D if (K > syou): K = K - syou if ((K % 2) == 0): print((abs(abs(X) - D * syou))) else: print((abs(abs(X)-D*(syou+1)))) else: print((abs(abs(X)-D*K)))
p02584
# -*- coding: utf-8 -*- x,k,d=list(map(int,input().split())) m=abs(x) n=0 for i in range(k): if x<0: x+=d else: x-=d if abs(x)<m: m=abs(x) else: n=k-i break if n%2==0: print(m) else: print((abs(x)))
# -*- coding: utf-8 -*- x,k,d=list(map(int,input().split())) m=abs(x) n=m//d j=k-n if j>0: if x<0: if j%2==0: x+=d*n else: x+=d*(n+1) else: if j%2==0: x-=d*n else: x-=d*(n+1) else: if x<0: x+=d*k else: x-=d*k print((abs(x)))
p02584
X,K,D=list(map(int,input().split())) i=0 count=0 if X<0: if X+K*D<=0: print((abs(X+K*D))) count+=1 else: L=X+i*D while L<=0: i+=1 L=X+i*D if abs(L)>=abs(X+(i+1)*D): i+=1 L=abs(X+i*D) else: if X-K*D>=0: print((abs(X-K*D))) count+=1 else: L=X-i*D while L>=0: i+=1...
X,K,D=list(map(int,input().split())) X=abs(X) count=0 if X-K*D>=0: print((X-K*D)) else: s=int(X/D) kaisuu=K-s if kaisuu%2==0: print((abs(X-s*D))) else: print((abs(X-(s+1)*D)))
p02584
x,k,d = list(map(int, input().split())) x_min = abs(x) for i in range(k): if x < 0: x += d if abs(x) < x_min: x_min = abs(x) else:#xが0以上 if (k - i - 1) % 2 == 1: break else: x_min = d - x_min brea...
x,k,d = list(map(int, input().split())) if x < 0: x = -x x_min = x if x//d >= k: x_min -= k * d else: x_min -= x//d * d k -= x//d if k % 2 == 1: x_min = abs(x_min - d) print(x_min) #xが更新されてる!!
p02584
x, k, d = list(map(int, input().split())) if abs(x)-d*k>=0: print((abs(x)-d*k)) exit() num = 0 while k>0: s = abs(x) s = s-d if abs(s)>=abs(x): break x = abs(s) k -= 1 if k == 0: print((abs(s))) exit() if k%2 == 0: print((abs(x))) else: ...
x, k, d = list(map(int, input().split())) n = abs(x)//d if n>=k: print((abs(x)-d*k)) else: if (k-n)%2 == 0: print((abs(abs(x)-d*n))) else: print((abs(abs(x)-d*(n+1))))
p02584
x,k,d=list(map(int,input().split())) m=0 p=0 eo=k ans=x for i in range(1,k+1): m,p=abs(ans-d),abs(ans+d) ans=min(m,p) if ans<=d: eo=i break if (k-eo)%2==0 and eo<k: print(ans) elif (k-eo)%2==1 and eo<k: print((abs(ans-d))) else: print(ans)
x,k,d=list(map(int,input().split())) if abs(x)-k*d>=0: print((abs(x)-k*d)) else: xx,kk=abs(x)-d*(abs(x)//d),k-(abs(x)//d) if kk%2==0: print((abs(xx))) else: print((abs(xx-d)))
p02584
import os import sys from io import BytesIO, IOBase def main(): x,k,d = list(map(int,input().split())) t = x//d if t<=k and x<0: x+=t*d k-=t elif t<=k and x>0: x-=t*d k-=t elif t>k and x<0: x+=k*d k-=k elif t>k and x>0: ...
import os import sys from io import BytesIO, IOBase def main(): x,k,d = list(map(int,input().split())) t = abs(x)//d if t<=k and x<0: x+=t*d k-=t elif t<=k and x>0: x-=t*d k-=t elif t>k and x<0: x+=k*d k-=k elif t>k a...
p02584
N, K = list(map(int ,input().split(' '))) P = list(map(int ,input().split(' '))) P_set = [ P[i:i+K] for i in range(0, len(P)) if len(P[i:i+K])==K] E = [] for dices in P_set: E.append(sum([sum([i for i in range(1,dice+1)]) / float(dice) for dice in dices])) print(('{:.12f}'.format(max(E))))
N, K = list(map(int ,input().split(' '))) P = list(map(int ,input().split(' '))) dct = {} for i in range(0, len(P)): if len(P[i:i+K])==K: p_k = P[i:i+K] dct[sum(p_k)] = p_k E = sum([sum([i for i in range(1,dice+1)]) / dice for dice in dct[max(dct)]]) print(('{:.12f}'.format(E)))
p02780
N, K = list(map(int ,input().split(' '))) P = list(map(int ,input().split(' '))) dct = {} for i in range(0, len(P)): if len(P[i:i+K])==K: p_k = P[i:i+K] dct[sum(p_k)] = p_k E = sum([sum([i for i in range(1,dice+1)]) / dice for dice in dct[max(dct)]]) print(('{:.12f}'.format(E)))
N, K = list(map(int ,input().split(' '))) P = list(map(int ,input().split(' '))) max_k = 0 max_v = [] for i in range(0, len(P)): if len(P[i:i+K])==K: p_k = P[i:i+K] if max_k<=sum(p_k): max_k=sum(p_k) max_v=p_k E = sum([sum([i for i in range(1,dice+1)]) / dice fo...
p02780
import math n,k = input().split() p = input().split() n = int(n) k = int(k) ex =0 ext = [] ext2 = [] for f in range(n): xs = list(range(1,int(p[f])+1)) xs = sum(xs)*1/int(p[f]) ext.append(xs) ext2.append(ext[0]) for i in range(1,n): ext2.append(ext2[i-1]+ext[i]) ex = ext2[k-1] ...
import math n,k = input().split() p = input().split() n = int(n) k = int(k) #p = [int(s) for s in p] #print(p) ex =0 ext = [] ext2 = [] for f in range(n): pi = int(p[f]) xs =(pi+1)/2 ext.append(xs) ext2.append(ext[0]) for i in range(1,n): ext2.append(ext2[i-1]+ext[i]) ex = e...
p02780
N, K = list(map(int, input().split())) p = list(map(int, input().split())) pos = 0 saidai = 0 for i in range(N-K+1): temp = sum(list([(x+1)/2 for x in p[i:i+K]])) if saidai < temp: saidai = temp print(('{:.12f}'.format(saidai)))
N, K = list(map(int, input().split())) p = list(map(int, input().split())) now = sum(p[:K]) saidai = now for i in range(K, N): now -= p[i-K] now += p[i] if now > saidai: saidai = now print(('{:.12f}'.format((saidai + K)/2)))
p02780
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) for i in range(len(p)): p[i] = p[i] + 1 queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] queue.put(p[i]) if i >= K: currentSum = current...
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] + 1 queue.put(p[i] + 1) if i >= K: currentSum = currentSum - queue.get() if i >= K - 1: ...
p02780
import queue N, K = list(map(int, input().split())) p = list(map(int, input().split())) queue = queue.Queue() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] + 1 queue.put(p[i] + 1) if i >= K: currentSum = currentSum - queue.get() if i >= K - 1: ...
from collections import deque N, K = list(map(int, input().split())) p = list(map(int, input().split())) queue = deque() currentSum = 0 maxSum = 0 for i in range(len(p)): currentSum = currentSum + p[i] + 1 queue.append(p[i] + 1) if i >= K: currentSum = currentSum - queue.popleft() ...
p02780
N, K = list(map(int, input().split())) p = list(map(int, input().split())) max = 0 for i in range(N-K+1): tmp = p[i] # print("i:" + str(i)) for j in range(i+1,i+K): tmp += p[j] # print(tmp) if(max < tmp): max = tmp maxStartIndex = i ans = 0 for i in range(...
N, K = list(map(int, input().split())) p = list(map(int, input().split())) p_sum = [0] max = 0 for i in range(len(p)): p_sum.append(p_sum[i] + (p[i]+1)/2) for i in range(K,N+1): sum = p_sum[i] - p_sum[i-K] if(max < sum): max = sum # for i in range(N-K+1): # tmp = p[i] # # pr...
p02780
n, k = list(map(int, input().split())) p = list(map(int, input().split())) ki = [0]*1001 for i in range(1, 1001): ki[i] = ki[i-1]+i pp = [] for pa in p: pp.append(ki[pa]/pa) ans = 0 for i in range(n-k+1): ans = max(ans, sum(pp[i:i+k])) print(("{0:.12f}".format(ans)))
import itertools n, k = list(map(int, input().split())) p = list(map(int, input().split())) ki = [0]*1001 for i in range(1, 1001): ki[i] = ki[i-1]+i pp = [] for pa in p: pp.append(ki[pa]/pa) # print(pp) ppp = [0] + list(itertools.accumulate(pp)) # print(ppp) ans = 0 for i in range(n-k+1): ...
p02780
import sys import math from collections import deque from collections import defaultdict def main(): n, k = list(map(int,sys.stdin.readline().split())) p = list(map(int,sys.stdin.readline().split())) sum_max = 0 max_idx = 0 for i in range(n - k + 1): max_tmp = 0 for j in...
import sys import math from collections import deque from collections import defaultdict def main(): n, k = list(map(int,sys.stdin.readline().split())) p = list(map(int,sys.stdin.readline().split())) sum_l = [0] * (n - k + 1) for i in range(k): sum_l[0] += p[i] for i in range(1,n...
p02780
N,K = list(map(int,input().split())) p = list(map(int,input().split())) expectation=[] E = [] #期待値 for t in p: value = 0 for x in range(t+1): value += x/t E.append(value) for t in range(N-(K-1)): value = 0 for i in range(K): value += E[t+i] expectation.append(va...
N,K = list(map(int,input().split())) p = list(map(int,input().split())) E = [] value=0 #期待値の計算,累積和の計算 for P_i in p: value += (1+P_i)/2 E.append(value) flag = E[K-1] #隣接するK項の計算 for k in range(K,N): S = E[k] - E[k-K] if flag < S: flag = S print((format(flag,'.12f')))
p02780
import math N, K = list(map(int, input().split())) P = list(map(int, input().split())) INDEX = -1 MA = 0 for i in range((N - K + 1)//2): M = 0 L = 0 for j in range(K): M += P[i + j] L += P[-1-i-j] # print(L) if M > MA: MA = M INDEX = i if L > MA: ...
import math N, K = list(map(int, input().split())) P = list(map(int, input().split())) INDEX = 0 total = 0 for i in range(K): total += P[i] tmp = total for i in range(N - K): tmp = tmp - P[i] + P[i + K] if tmp > total: total = tmp INDEX = i+1 # MA = 0 # for i in r...
p02780
#python3 def f(x): return (x+1)/2 def main(): n, k = list(map(int, input().split())) fp = [f(int(i)) for i in input().split()] n = len(fp) v = sum(fp[0:k]) i = 0 ans = v while i+k <= n-1: v = v-fp[i]+fp[i+k] ans = max(ans, v) i+=1 a = "{0:...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def E(x): return (x*(x+1)//2)/x def main(): N, K = list(map(int, readline().split())) e = [E(int(i)) for i in readline().split()] s = [0.] for i in range(N): s.app...
p02780
N,K = list(map(int,input().split())) p = list(map(int,input().split())) def exp(n): if n % 2 == 0: s = (n+1)*n/2 else: s = (n+1)*(n-1)/2+(n+1)/2 ans = s / n return ans M = 0 for i in range(N-K+1): S = 0 for j in range(K): S += exp(p[i+j]) if M < S: ...
N,K = list(map(int,input().split())) p = list(map(int,input().split())) def exp(n): if n % 2 == 0: s = (n+1)*n/2 else: s = (n+1)*(n-1)/2+(n+1)/2 ans = s / n return ans q = [] for i in range(N): q.append(exp(p[i])) #print(q) S = sum([q[i] for i in range(K)]) M = S ...
p02780
import sys input = sys.stdin.readline """ 後ろから、到達不可能距離の集合を見ていきたい。 集合を持つと厳しいが、最小値だけ持っておけばよい。 """ N,dist = list(map(int,input().split())) D = [int(x) for x in input().split()] # 各ターンの出発位置 start_dist = [dist] for d in D: x = start_dist[-1] y = min(abs(x - d), x) start_dist.append(y) ng_di...
import sys input = sys.stdin.readline """ 後ろから、到達不可能距離の集合を見ていきたい。 集合を持つと厳しいが、最小値だけ持っておけばよい。 """ N,dist = list(map(int,input().split())) D = [int(x) for x in input().split()] # 各ターンの出発位置 start_dist = [dist] for d in D: x = start_dist[-1] y = x-d if x > d else d - x start_dist.append(x if x...
p03743
N, D = list(map( int, input().split() )) d = list( map( int, input().split() ) ) Q = int( eval(input()) ) q = list( map( int, input().split() ) ) dis = [ 0 for i in range( N + 1 ) ] dis[ 0 ] = D for i in range( N ): dis[ i + 1 ] = min( dis[ i ], abs( dis[ i ] - d[ i ] ) ) dp = [ 0 for i in range( N + 1 ) ...
N, D = list(map( int, input().split() )) d = list( map( int, input().split() ) ) Q = int( eval(input()) ) q = list( [int( x ) - 1 for x in input().split()] ) dis = [ 0 for i in range( N + 1 ) ] dis[ 0 ] = D for i in range( N ): dis[ i + 1 ] = min( dis[ i ], abs( dis[ i ] - d[ i ] ) ) dp = [ 0 for i in ran...
p03743
n, D = list(map(int, input().split())) x = list(map(int, input().split())) Q = int(eval(input())) q = list(map(int, input().split())) ind = [D] for i in range(n): ind.append(min(ind[-1], abs(ind[-1] - x[i]))) #print(ind) l = [1] for i in range(n-1, -1, -1): if x[i] < 2*l[-1]: l.append(x[i] + l[-1]) ...
n, D = list(map(int, input().split())) x = list(map(int, input().split())) Q = int(eval(input())) q = list(map(int, input().split())) ind = [D] for i in range(n): ind.append(min(ind[-1], abs(ind[-1] - x[i]))) l = [1] for i in range(n-1, -1, -1): if x[i] < 2*l[-1]: l.append(x[i] + l[-1]) else: l.a...
p03743
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] day = day[::-1] i = day.index(S) print((i+1))
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) S = sr() days = 'SUN,MON,TUE,WED,THU,FRI,SAT'.split(',') day_to_x = {x: 7 - i for i, x in enumerate(days)} print((day_to_x[S]))
p02847
import sys import collections def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 d = collections.defaultdict(int) d["SUN"] = 7 d["MON"] = 6 d["TUE"] = 5 d["WED"] = 4 d["THU"] = 3 d["FRI"] = 2 d["SAT"] = 1 print((d[str(readline().rstrip().deco...
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 d = {v: 7 - i for i, v in enumerate("SUN,MON,TUE,WED,THU,FRI,SAT".split(","))} print((d[str(readline().rstrip().decode('utf-8'))])) if __name__ == '__main__': solve()
p02847
from sys import stdin def b(input_string): _s = input_string s_length = len(_s) s = [] for i in range(s_length): s.append(_s[i]) #print(_s) #print(s) count = 0 flag = True while flag and len(s) >= 2: flag = False for i in range(s_length): ...
from sys import stdin def b(input_string): _s = input_string s_length = len(_s) s = [] for i in range(s_length): s.append(_s[i]) count = 0 i = 0 while(i < len(s)-1): #print(s) #print(i) if s[i] != s[i+1]: s.pop(i) s.po...
p03107
S = input() N = len(S) count = 0 tmp = 1 dst = S while True: dst1 = dst.replace('01', '') dst2 = dst1.replace('10', '') if len(dst) - len(dst2) <= 0: break count += len(dst) - len(dst2) dst = dst2 print(count)
S = input() print((min(S.count('1'), S.count('0')) * 2))
p03107
S=input().strip() N=len(S) q = [S] while q: s = q.pop() p = '' v = 0 for i,c in enumerate(s): if (p == '0' and c == '1') or (p == '1' and c == '0'): q.append(s[:i-1]+s[i+1:]) v += 1 p = c if v == 0: print((N-len(s))) break
S=input().strip() N=len(S) a=[0 if x == '0' else 1 for x in S] while True: v = 0 p = -1 b = [] for i in a: if p >= 0: if p == 0 or p == 1: if i == 0 or i == 1: if p != i: p = -1 v += ...
p03107
S = input() S = str(S) counter = 0 while True: killer = 0 killer += int(S.count('10')) S = S.replace('10','') killer += int(S.count('01')) S = S.replace('01','') counter += int(killer) if killer == 0: break print(counter * 2)
S = input() S = str(S) S_1 = int(S.count('1')) S_0 = int(S.count('0')) if S_1 > S_0: print(S_0 * 2) else: print(S_1 * 2)
p03107
def compute(): from sys import stdin S = stdin.readline().strip() wew = [] for x in S: if len(wew)>0 and wew[-1]!=x: wew.pop() else: wew.append(x) print((len(S) - len(wew))) if __name__ == "__main__": compute()
def compute(): from sys import stdin S = stdin.readline().strip() l = len(S) x = S.count("1") y = min(x, l-x) print((y<<1)) if __name__ == "__main__": compute()
p03107
S=input() A=[s for s in S] while True: A_new=[] i=0 while i<len(A): if i<len(A)-1: if A[i]!=A[i+1]: i+=2 else: A_new.append(A[i]) i+=1 else: A_new.append(A[i]) i+=1 if A==A_ne...
S=input() A=[] Ans=0 for i in range(len(S)): if len(A)>0: if A[-1]!=S[i]: A.pop() Ans+=2 else: A.append(S[i]) else: A.append(S[i]) print(Ans)
p03107
#!/usr/bin/env python3 import sys def solve(S: str): n = len(S) while True: l = len(S) for i in range(len(S) - 1): if S[i] != S[i + 1]: S = S[:i] + S[i + 2:] break if l == len(S): break print((n - len(S))) r...
#!/usr/bin/env python3 import sys def solve(S: str): n = len(S) while True: l = len(S) i = 0 while True: if i >= len(S) - 1: break if S[i] != S[i + 1]: S = S[:i] + S[i + 2:] i = max(i - 1, 0) ...
p03107
import re bit_string = input() replaced_count = 0 replaced_string = bit_string while re.search('01|10', replaced_string): replaced_string, tmp_count = re.subn('01|10', '', replaced_string) replaced_count += tmp_count print((replaced_count * 2))
bit_string = input() count_zero = bit_string.count('0') count_one = bit_string.count('1') print((min(count_zero, count_one) * 2))
p03107
#!/usr/bin/env python3 import sys def solve(S: str): nS = len(S) pS = "" while pS != S: pS = S S = S.replace("01", "") S = S.replace("10", "") print((nS - len(S))) def main(): def iterate_tokens(): for line in sys.stdin: for word in li...
#!/usr/bin/env python3 import sys def solve(S: str): print((min(S.count("0"), S.count("1")) * 2)) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() S = next(tokens) # type: str ...
p03107
S = input(); cnt = 0; while True: for i in range(len(S)): tmp = S.replace('01', '', 1); if S != tmp: cnt += 2; S = tmp; break; tmp = S.replace('10', '', 1); if S != tmp: cnt += 2; S = tmp; break; if len(set(S)) <= 1: break; print(cnt);
S = input(); S1 = S.count('1'); S0 = S.count('0'); if S1 > S0: print(S0 * 2); else: print(S1 * 2);
p03107
import sys import re s = sys.stdin.read().strip() n = len(s) while len(re.findall("10|01", s)) > 0: s = re.sub("10|01", "", s) print((n - len(s)))
import sys s = sys.stdin.read().strip() n = len(s) print((2 * min(s.count("0"), s.count("1"))))
p03107
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)] s, = read_line(str) s = [int(c) for c in s] c = 0 while True: i = 0 while i < len(s) - 1: if s[i] != s[i + 1]: s[i] = s[i + 1] = -1 i += 2 c += 2 i += 1 s = [c f...
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)] s, = read_line(str) s = [int(c) for c in s] c = 0 ss = 0 for i in range(0, len(s)): if s[i] == 1: if ss < 0: c += 2 ss += 1 else: if ss > 0: c += 2 ss -= 1 ...
p03107
import sys input = sys.stdin.readline S=list(input().strip()) flag=True cnt=0 i=0 f=[] if len(S) != 1: while flag: if S[i] != S[i+1]: f.append(i) f.append(i+1) i+=2 else: i+=1 if i>=len(S)-1: cnt+=len(f) ...
import sys input = sys.stdin.readline S=list(input().strip()) zero=S.count('0') one=S.count('1') print((min(zero,one)*2))
p03107
def remove01Pair(R): for i in range(len(R) - 1): #print(i) if R[i:i + 2] == '01': R = R[:i] + R[i + 2:] #print(R) return R flag[0] = 1 return R def remove10Pair(R): for i in range(len(R) - 1): #print(i) if R[i:i + 2] == '1...
N = input().strip() #print(N) length = len(N) #print(length) totalZeros = 0 totalOnes = 0 for i in N: if i == '0': totalZeros += 1 else: totalOnes += 1 if totalOnes < totalZeros: answer = totalOnes * 2 else: answer = totalZeros * 2 print(answer)
p03107
import sys input = sys.stdin.readline import re def print_ans(S): """Test Case >>> print_ans("0011") 4 >>> print_ans("11011010001011") 12 >>> print_ans("0") 0 """ flg = True ans = 0 while flg: tmp = re.sub(r"01|10", "", S) if len(tmp) == len(S)...
import sys input = sys.stdin.readline import re def print_ans(S): """Test Case >>> print_ans("0011") 4 >>> print_ans("11011010001011") 12 >>> print_ans("0") 0 """ flg = True ans = 0 # while flg: # tmp = re.sub(r"01|10", "", S) # if len(tmp) == ...
p03107
# -*- coding: utf-8 -*- S = input().strip() #----- cnt=0 while (S.count("01") != 0) or (S.count("10") != 0): cnt += S.count("01") S = S.replace("01", "") cnt += S.count("10") S = S.replace("10", "") print((cnt*2))
# -*- coding: utf-8 -*- S = input().strip() #----- num_red = S.count("0") num_blue = len(S) - num_red print(( min(num_red,num_blue) * 2 ))
p03107
# -*- coding: utf-8 -*- def main(): s = input().split(" ") sl = list(s[0]) prev = -1 n = 0 while True: # print(str(sl)) if len(sl) < 1: break kita = False for i, c in enumerate(sl): if i == 0 and prev != -1: bre...
# -*- coding: utf-8 -*- def main(): s = input().split(" ") sl = list(s[0]) prev = -1 n = 0 i = 0 while True: if len(sl) <= i: break if (prev == 0 and sl[i] == '1') or (prev == 1 and sl[i] == '0'): # print(str(sl)) # print("r...
p03107
#!usr/bin/env python3 from collections import defaultdict from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, sys.stdin.readline().split())) ...
#!usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS():return list(map(list, ...
p03107
import sys def solve(): input = sys.stdin.readline zero, one = 0, 0 s = input().strip("\n") for i in range(len(s)): if s[i] == "0": zero += 1 else: one += 1 print((2 * min(zero, one))) return 0 if __name__ == "__main__": solve()
import sys def solve(): input = sys.stdin.readline S = input().strip("\n") zero, one = 0, 0 for i in range(len(S)): if S[i] == "0": zero += 1 else: one += 1 print((2 * min(zero, one))) return 0 if __name__ == "__main__": solve()
p03107
S = input().strip() N = len(S) k = 0 for i in range(N): if S[i]=="0": k += 1 m = min(k,N-k) print((2*m))
S = input().strip() N = len(S) cnt = 0 for i in range(N): if S[i]=="1": cnt += 1 print((min(cnt,N-cnt)*2))
p03107
S = input().strip() N = len(S) cnt = 0 for i in range(N): if S[i]=="1": cnt += 1 print((min(cnt,N-cnt)*2))
S = input().strip() cnt0 = 0 cnt1 = 0 for i in range(len(S)): if S[i]=="0": cnt0 += 1 else: cnt1 += 1 print((min(cnt0,cnt1)*2))
p03107
import sys fin = sys.stdin.readline import copy ob = list(fin()) for i in range(len(ob)-1): if ob[i]=="0" and ob[i+1]=="1": ob[i]="1" ob[i+1]="0" n = len(ob) while True: ob_sub = copy.copy(ob) j=0 for i in range(len(ob)-1): if ob[i]=="1" and ob[i+1]=="0":...
import sys fin = sys.stdin.readline ob = list(fin()) print((min(ob.count("0"), ob.count("1"))*2))
p03107
s=input().count;print((min(s('0'),s('1'))*2))
print((min(list(map(input().count,'01')))*2))
p03107
# デバッグ用 GBN_DEBUG = False GBN_DEBUG = True def dprn(s, i): if GBN_DEBUG: print(", " + s + " = " + str(i), end = "") def dprns(s): if GBN_DEBUG: print(", " + s, end = "") def dprni(i): if GBN_DEBUG: print(i, end=" ") def endl(): if GBN_DEBUG: print('') def puts(s): print(s) #本体ここから S = ...
# デバッグ用 GBN_DEBUG = False GBN_DEBUG = True def dprn(s, i): if GBN_DEBUG: print(", " + s + " = " + str(i), end = "") def dprns(s): if GBN_DEBUG: print(", " + s, end = "") def dprni(i): if GBN_DEBUG: print(i, end=" ") def endl(): if GBN_DEBUG: print('') def puts(s): print(s) #本体ここから S = ...
p03107
import sys s = str(sys.stdin.readline()) o = len(s) for i in range(1000000000000): p1 = s.find("01") p2 = s.find("10") if p1 == -1 and p2 == -1: break elif p1 == -1: i = p2 elif p2 == -1: i = p1 else: i = p1 if p1 < p2 else p2 s = s[:i] + s[i...
import sys s = str(sys.stdin.readline()) c0 = s.count('0') c1 = s.count('1') r = c0 if c0 < c1 else c1 print((r*2))
p03107
l = input().split() s = l[0] def get_removals(s): ret = [] for i in range(len(s) - 1): if int(s[i]) + int(s[i + 1]) == 1: ret.append(i) return ret def remove(s, index): if index == 0: return s[2:] if index == (len(s) - 1): return s[:index-1] r...
l = input().split() s = l[0] def get_removals(s): ret = [] for i in range(len(s) - 1): if int(s[i]) + int(s[i + 1]) == 1: ret.append(i) return ret def remove(s, index): if index == 0: return s[2:] if index == (len(s) - 1): return s[:index-1] r...
p03107
import copy s = input().split()[0] def get_kouho_list(box_list): kouho_list = [] for i, color in enumerate(box_list[:-1]): if box_list[i] != box_list[i+1]: kouho_list.append((i, i+1)) return kouho_list def tansaku(now_box_list, koremade_step): kouho_list = get_kouho_li...
import collections s = input().split()[0] counter = collections.Counter(list(s)) c_0 = counter['0'] c_1 = counter['1'] step = min(c_0, c_1) print((step * 2))
p03107
from sys import stdin import re S = stdin.readline().rstrip() before_S = S while(True): #after_S = S.replace("01", "").replace("10", "") after_S = re.sub("(01)+|(10)+", "", S) if len(after_S) != len(S): S = after_S else: break print((len(before_S) - len(S)))
from sys import stdin S = stdin.readline().rstrip() stack = [] count = 0 for s in S: # スタックが空なら if not stack: stack.append(s) # スタックの一番上がsでなければ elif stack[-1] != s: stack.pop() count += 2 else: stack.append(s) print(count)
p03107
from itertools import chain def f(s): l = s.split('01') for i in range(len(l)): l[i] = l[i].split('10') l = list(chain.from_iterable(l)) return l s = input().rstrip() count = 0 while True: l = f(s) if len(l) == 1: break count += (len(l) - 1) * 2 s ...
s = input().rstrip() print((2 * min(s.count('0'), s.count('1'))))
p03107
#!usr/bin/env python3 import sys class Die: def __init__(self, pips): self.pips = pips def move_die(self, direction): tmp = int() if direction == 'N': tmp = self.pips[0] self.pips[0] = self.pips[1] self.pips[1] = self.pips[5] ...
#!usr/bin/env python3 import sys class Die: def __init__(self, pips): self.pips = pips def move_die(self, direction): if direction == 'N': tmp = self.pips[0] self.pips[0] = self.pips[1] self.pips[1] = self.pips[5] self.pips[5] = s...
p02384
class Dice: def __init__(self, labels): self.labels = labels def east(self): self.labels[1], self.labels[2], self.labels[3], self.labels[4] = self.labels[3], self.labels[1], self.labels[4], self.labels[2] def west(self): self.labels[1], self.labels[2], self.labels[3], self.labe...
class Dice: def __init__(self, labels): self.labels = labels def east(self): self.labels[0], self.labels[2], self.labels[5], self.labels[3] = self.labels[3], self.labels[0], self.labels[2], self.labels[5] def west(self): self.labels[0], self.labels[2], self.labels[5], self.labe...
p02384
class Dice: def __init__(self): self.up = 1 self.under = 6 self.N = 5 self.W = 4 self.E = 3 self.S = 2 def roll(self, d):#d => direction if d == "N": tmp = self.up self.up = self.S self.S = self.under ...
class Dice: def __init__(self): self.up = 1 self.under = 6 self.N = 5 self.W = 4 self.E = 3 self.S = 2 def roll(self, d):#d => direction if d == "N": tmp = self.up self.up = self.S self.S = self.under ...
p02384
class Dice: def __init__(self): # 初期値がない場合 # 上, 南、東、西、北、下にそれぞれ1, 2, 3, 4, 5, 6がくる想定 self.t = 1 self.s = 2 self.e = 3 self.w = 4 self.n = 5 self.b = 6 self.rotway = {"S": 0, "N": 1, "E": 2, "W": 3} def __init__(self, t, s, e, ...
rot_set = [ (1,2,4,3,1), #0 (0,3,5,2,0), #1 (0,1,5,4,0), #2 (0,4,5,1,0), #3 (0,2,5,3,0), #4 (1,3,4,2,1) #5 ] dice_int = list(map(int, input().split())) q = int(eval(input())) right_face = [] for _ in range(q): a, b = list(map(int, input().split())) a_idx = dice_int.inde...
p02384
from sys import stdin from copy import deepcopy import queue class Dice: def __init__(self, nums): self.labels = [None] + [ nums[i] for i in range(6) ] self.pos = { "E" : 3, "W" : 4, "S" : 2, "N" : 5, "T" : 1, "B" ...
from sys import stdin from copy import deepcopy import queue class Dice: def __init__(self, nums): self.labels = [None] + [ nums[i] for i in range(6) ] self.pos = { "E" : 3, "W" : 4, "S" : 2, "N" : 5, "T" : 1, "B" ...
p02384
# coding: utf-8 # ?????????????????¨???????????? class Dice(object): def __init__(self): # ????????¶??? self.dice = (2, 5), (3, 4), (1, 6) # x, y, z self.ax = [[0, False], [1, False], [2, False]] self.axmap = [0, 1, 2] self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (...
# coding: utf-8 # ?????????????????¨???????????? class Dice(object): def __init__(self): # ????????¶??? self.dice = (2, 5), (3, 4), (1, 6) # x, y, z self.ax = [[0, False], [1, False], [2, False]] self.axmap = [0, 1, 2] self.mm = {"N": (0, 2), "S": (2, 0), "E": (1, 2), "W": (2, 1), "R": (0, 1), "L": (...
p02384
# 2019-11-17 20:44:23(JST) import sys # import collections # import math # from string import ascii_lowercase, ascii_uppercase, digits # from bisect import bisect_left as bi_l, bisect_right as bi_r # import itertools # from functools import reduce # import operator as op # import re # import heapq # import a...
import sys s, t = sys.stdin.read().split() def main(): cnt = 0 for i in range(3): if s[i] == t[i]: cnt += 1 return cnt if __name__ == '__main__': ans = main() print(ans)
p02921
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): s = gete() t =...
import sys from collections import defaultdict readline = sys.stdin.buffer.readline #sys.setrecursionlimit(10**8) def geta(fn=lambda s: s.decode()): return list(map(fn, readline().split())) def gete(fn=lambda s: s.decode()): return fn(readline().rstrip()) def main(): s = gete() t =...
p02921
import queue nv, ne = map(int, input().split(' ')) in_degrees = [[] for _ in range(nv)] q = queue.Queue() o = [] for _ in range(ne): s, t = map(int, input().split(' ')) in_degrees[t].append(s) for i in range(nv): if len(in_degrees[i]) == 0: q.put(i) while not q.empty(): v = q.get() ...
import queue nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = queue.Queue() outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.put(i) ...
p02370
import queue nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = queue.Queue() outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.put(i) ...
nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = [] outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.append(i) while len(q) > 0: ...
p02370
nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = [] outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.append(i) while len(q) > 0: ...
nv, ne = map(int, input().split(' ')) in_degs = [0] * nv q = [] outs = {} o = [] for _ in range(ne): s, t = map(int, input().split(' ')) if s in outs: outs[s].append(t) else: outs[s] = [t] in_degs[t] += 1 for i in range(nv): if in_degs[i] == 0: q.append(i) while q: v = q.p...
p02370
def bfs(s): que = [s] used[s] = True while que: u = que.pop(0) ans.append(u) for v in G[u]: indeg[v] -= 1 if indeg[v] == 0 and not used[v]: used[v] = True que.append(v) def tsort(): for u in range(V): ...
def tsort(G): def bfs(s): que = [s] used[s] = True while que: u = que.pop(0) res.append(u) for v in G[u]: indeg[v] -= 1 if indeg[v] == 0 and not used[v]: used[v] = True qu...
p02370
#!/usr/bin/env python3 # ????????????????????°???????????°????????????????????\??????????????¢?????´???????????¨??????????§??????? import array import collections class TopologicalSortError(Exception): pass def topological_sort(num_vs, adj_vs): in_deg = array.array("L", (0 for _ in range(num_vs...
#!/usr/bin/env python3 import array import heapq def topological_sort(num_vs, adj_vs): """ Performs topological sorting of the given DAG. This function computes the lexicographically least topological order of the given DAG. :param num_vs int: The number of vertices. :param adj_vs ...
p02370
#!/usr/bin/env python3 import itertools def main(): N = int(eval(input())) F = [list(map(int,input().split())) for _ in range(N)] P = [list(map(int,input().split())) for _ in range(N)] bit_list = list(itertools.product([0, 1], repeat=10)) bit_list.pop(0) answer = -10**9-1 for b in...
#!/usr/bin/env python3 import itertools def main(): N = int(eval(input())) F = [int(input().replace(' ',''),2) for _ in range(N)] P = [list(map(int,input().split())) for _ in range(N)] answer = -float('inf') for bit in range(1,1<<10): tmp_profit = 0 for i in range(N): ...
p03503
#from collections import Counter N=int(eval(input())) F=list(list(map(int,input().split())) for i in range(N)) P=list(list(map(int,input().split())) for i in range(N)) ans=-(1<<40) for bit in range(1,1<<10): tmp = 0 for i in range(N): c=0 for j in range(10): if bit&(1<<j) a...
#from collections import Counter N=int(eval(input())) F=list(int(input().replace(" ",""),2) for i in range(N)) P=list(list(map(int,input().split())) for i in range(N)) ans=-(1<<40) for bit in range(1,1<<10): tmp = 0 for i in range(N): tmp+=P[i][bin(bit&F[i]).count('1')] ans = max(ans,tmp) ...
p03503
N=int(eval(input())) H=['']*N W=['']*N x=[] for i in range(N): H[i]=list(map(int,input().split())) for j in range(N): W[j]=list(map(int,input().split())) for k in range(1,1024): t=[] for ii in range(10): if k&(1<<ii): t+=[1] else: t+=[0] ans=0 ...
N=int(eval(input())) ans=-10**9 s=["".join(list(input().split())) for i in range(N)] t=[list(map(int,input().split())) for i in range(N)] for j in range(1,1024): q=0 for i in range(len(s)): q+=t[i][(bin(int(s[i],2)&j)).count("1")] ans=max(ans,q) print(ans)
p03503
# 写経 n = int(eval(input())) lst_F = [list(map(int, input().split())) for _ in range(n)] lst_P = [list(map(int, input().split())) for _ in range(n)] ans = -float("INF") for b in range(1, 2**10): tmp = 0 for i in range(n): c = 0 for k in range(10): if b&(1<<k) and lst_F...
N = int(eval(input())) lst_F = [list(map(int, input().split())) for _ in range(N)] lst_P = [list(map(int, input().split())) for _ in range(N)] n_timetable = 10 lst_joisino = [None] * n_timetable def score(src, F, P): cnt = 0 for i, j in zip(src, F): if i == j == 1: cnt += 1 ...
p03503
import sys input=sys.stdin.readline def main(): N = int(eval(input())) F = [] for _ in range(N): F.append(list(map(int, input().split()))) P = [] for _ in range(N): P.append(list(map(int, input().split()))) ans = -10**7*N for i in range(1, 1<<10): tmp ...
import sys input=sys.stdin.readline def main(): N = int(eval(input())) F = [int(input().replace(" ", ""), 2) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] ans = -10**7*N for i in range(1, 1<<10): tmp = 0 for j,f in enumerate(F): ...
p03503
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in tuple(product(...
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in tuple(product(...
p03503
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(tuple(map(int, input().split())) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for b in product((0, 1)...
# ABC080C - Shopping Street import sys input = sys.stdin.readline from itertools import product def main(): N = int(eval(input())) F = tuple(int(input().replace(" ", ""), 2) for _ in range(N)) P = tuple(tuple(map(int, input().split())) for _ in range(N)) ans = [] for i in range(1, 2 *...
p03503
from sys import stdin def main(): #入力 readline=stdin.readline N=int(readline()) F=[] for i in range(N): f=list(map(int,readline().split())) F.append(f) P=[] for i in range(N): p=list(map(int,readline().split())) P.append(p) max_res=-floa...
from sys import stdin def main(): #入力 readline=stdin.readline N=int(readline()) F=[] for i in range(N): f=int("".join(readline().strip().split(" ")),2) F.append(f) P=[] for i in range(N): p=list(map(int,readline().split())) P.append(p) m...
p03503
n = int(eval(input())) f = [list(map(int,input().split())) for i in range(n)] p = [list(map(int,input().split())) for i in range(n)] ans = -10**12 for i in range(1,1024): #print("i=",i) temp = 0 for j in range(n): #j = 0,1,2,..,n-1で店番号 fi = f[j] ci = sum([1 for k in range(10) if (i>...
n = int(eval(input())) f = [int(input().replace(" ",""),2) for i in range(n)] #数にしてしまう p = [list(map(int,input().split())) for i in range(n)] ans = -10**12 for i in range(1,1024): #print("i=",i) temp = 0 for j in range(n): #j = 0,1,2,..,n-1で店番号 fi = f[j] ci = bin(fi&i).count("1") #b...
p03503
f=lambda:[list(map(int,input().split())) for _ in range(n)] n=int(eval(input())) llf,llp=f(),f() a=-10**9 import itertools as it for t in it.product([0,1],repeat=10): if sum(t): lc=[sum(t[i]*lf[i] for i in range(10)) for lf in llf] a=max(a,sum(llp[i][lc[i]] for i in range(n))) print(a)
I=input;R=range;n=int(I()) lf=[int(I()[::2],2) for _ in R(n)] lp=[list(map(int,I().split())) for _ in R(n)] print((max(sum(p[bin(i&f).count('1')] for f,p in zip(lf,lp)) for i in R(1,1024))))
p03503
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() from collections import d...
def getN(): return int(eval(input())) def getNM(): return list(map(int, input().split())) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(eval(input())) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() from collections import d...
p03503
n = int(eval(input())) arr = [list(map(int, input().split())) for i in range(n)] arm = [list(map(int, input().split())) for j in range(n)] ans = -9999999999 for item in range(1, 1024): fund = 0 for i in range(n): cou = 0 for x in range(10): if (item >> x) % 2 == 1 and arr[...
def solve(): n = int(eval(input())) oc = [list(map(int, input().split())) for _ in range(n)] prof = [list(map(int, input().split())) for _ in range(n)] ans = -9999999999 for a in range(1, 1 << 10): res = 0 for i in range(n): cnt = 0 for x in range...
p03503
#!/usr/bin/env python3 #ABC80 C from operator import itemgetter import collections n = int(eval(input())) f = [list(map(int,input().split())) for _ in range(n)] p = [list(map(int,input().split())) for _ in range(n)] ma = -float('inf') for i in range(1,2**10): b = [0]*10 s = 0 sum = 0 f...
#!/usr/bin/env python3 #ABC80 C import sys import math import bisect sys.setrecursionlimit(1000000000) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import item...
p03503
n=int(eval(input())) S=[list(map(str,input().split())) for _ in range(n)] C=[list(map(int,input().split())) for _ in range(n)] A=[] for i in range(1,2**10): ans=0 X=format(i,'b').zfill(10) for j in range(n): cnt=0 for k in range(10): if S[j][k]=='1' and X[k]=='1': ...
n=int(eval(input())) S=[int(input().replace(' ',''),2) for _ in range(n)] C=[list(map(int,input().split())) for _ in range(n)] A=[] for i in range(1,2**10): ans=0 for j in range(n): cnt=bin(S[j]&i).count('1') ans+=C[j][cnt] A.append(ans) print((max(A)))
p03503
import sys import itertools # import collections # import math # import string # import bisect # import re # import itertools # import statistics # bit を使ってci を管理する def toBit(n): return bin(eval('0b' + str(n))) def main(): n = int(sys.stdin.readline().rstrip()) schedule = [toBit...
import sys import itertools # import collections # import math # import string # import bisect # import re # import itertools # import statistics # bit を使ってci を管理する def toBit(n): return eval('0b' + n) def main(): n = int(sys.stdin.readline().rstrip()) schedule = [toBit(''.join(s...
p03503
N = int(eval(input())) F = [list(map(int,input().split())) for i in range(N)] P = [list(map(int,input().split())) for i in range(N)] ans = -(10**7) * 10 * 100 for i in range(1,2**10): counter = [0]*N #店iとjoisinoのかぶっている数 tmp = 0 # for j in range(10): if (i>>j) & 1: for k in range(N):...
n = int(eval(input())) bits = [] for i in range(n): bit = int(input().replace(" ", ""), 2) bits.append(bit) p = [[int(item) for item in input().split()] for _ in range(n)] ans = - 10**9 for i in range(1,2**10): val = 0 for j,mise in enumerate(p): val += mise[bin(i & bits[j]).count("1")] ans...
p03503
N=int(eval(input())) M=[[0 for i in range(2**10)] for j in range(N)] K=[0]*(2**10) F=[list(map(int,input().split())) for _ in range(N)] P=[list(map(int,input().split())) for _ in range(N)] for i in range(2**10): for j in range(10): for k in range(N): if (i>>9-j)&1 and F[k][j]: #print(i,j)...
N = int(eval(input())) F = [list(map(int, input().split())) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] answer = [] for i in range(1, 2 ** 10): tmp = 0 for j in range(N): cnt = 0 for k in range(10): if (i >> k) & 1 and F[j][k]: cnt += 1 tmp += P[...
p03503
N = int(eval(input())) F = [list(map(int, input().split())) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] result = -float('inf') for i in range(1, 1024): t = 0 for j in range(N): c = 0 for k in range(10): c += (i >> k & 1) & F[j][k] t ...
# ビット全探索 from itertools import product N = int(eval(input())) F = [list(map(int, input().split())) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] result = -float('inf') for i in product([True, False], repeat=10): if i.count(False) == 10: continue t = 0 for j...
p03503
N = int(eval(input())) F = [list(map(int, input().split())) for i in range(N)] P = [list(map(int, input().split())) for i in range(N)] ans = -10 ** 10 for b in range(1, 2 ** 10): bin_str = format(b, '010b') p = 0 for i in range(N): c = 0 for j in range(10): c += F[i][...
N = int(eval(input())) F = [list(map(int, input().split())) for i in range(N)] P = [list(map(int, input().split())) for i in range(N)] ans = -10 ** 10 def calc(b): p = 0 for i in range(N): c = 0 for j in range(10): c += F[i][j] * b[j] p += P[i][c] return p ...
p03503
N = int(eval(input())) F = [[0 for _ in range(10)] for _ in range(N)] P = [[0 for _ in range(10)] for _ in range(N)] for i in range(N) : F[i] = list(map(int, input().split())) for i in range(N) : P[i] = list(map(int, input().split())) ans = -float('inf') for mask in range(1, 2**10) : profit = 0...
N = int(eval(input())) F = [] for _ in range(N): mask = 0 for f in map(int, input().split()): mask <<= 1 mask |= f F.append(mask) P = [list(map(int, input().split())) for _ in range(N)] def calc(state): ret = 0 for f, ps in zip(F, P): f &= state cnt...
p03503
import sys from itertools import product input = sys.stdin.readline N = int(eval(input())) F = [[int(x) for x in input().split()] for _ in range(N)] P = [[int(x) for x in input().split()] for _ in range(N)] ans = float('-inf') for ptn in product([0, 1], repeat=10): if sum(ptn) == 0: continue ...
import sys input = sys.stdin.readline N = int(eval(input())) F = [int(input().replace(' ', ''), 2) for _ in range(N)] P = [[int(x) for x in input().split()] for _ in range(N)] ans = float('-inf') for i in range(1, 2**10): res = 0 for f, p in zip(F, P): cnt = bin(i & f).count('1') ...
p03503
from operator import mul n = int(eval(input())) cof = [1 << x for x in range(10)] fs = [sum(map(mul, list(map(int, input().split())), cof)) for _ in range(n)] ps = [list(map(int, input().split())) for _ in range(n)] ans = float('-inf') for g in range(1, 1024): ans = max(ans, sum(p[bin(f & g).count('1')] f...
N=int(eval(input())) F=[int(input().replace(' ',''),2) for i in range(N)] P=[list(map(int,input().split())) for i in range(N)] print((max(sum([p[bin(f&i).count('1')] for f,p in zip(F,P)]) for i in range(1,2**10))))
p03503
n = int(eval(input())) F = [] # for _ in range(n): # f = list(map(int, input().split())) # # print(f) # F.append([\ # [f[0],f[1]],\ # [f[2],f[3]],\ # [f[4],f[5]],\ # [f[6],f[7]],\ # [f[8],f[9]]\ # ]) for _ in range(n): f = list(map(int, input()....
n = int(eval(input())) F = [[*list(map(int, input().split()))] for _ in range(n)] P = [[*list(map(int, input().split()))] for _ in range(n)] def c(i, open_patern): ret = 0 for j in range(10): if open_patern>>j & 1: #open my shop if F[i][j]: ret += 1 # open your shop return ret ...
p03503
import sys input = sys.stdin.readline from itertools import combinations def readlines(n): for _ in range(n): yield list(map(int,input().split())) def bene(me, f, p): a = sum(1 if f[m] == 1 else 0 for m in me) return p[a] def main(): n = int(eval(input())) F = list(readlines...
import sys input = sys.stdin.readline from itertools import combinations def readlines(n): for _ in range(n): yield list(map(int,input().split())) def bene(me, f, p): a = len([0 for m in me if f[m] == 1]) return p[a] def main(): n = int(eval(input())) F = list(readlines(n)) ...
p03503
n = int(eval(input())) F = [list(map(int, input().split())) for _ in range(n)]#F[i]は(i+1)番目の店の営業の有無のリスト P = [list(map(int, input().split())) for _ in range(n)]#P[i]は(i+1)番目の店との同時開店数に応じた利益のリスト ans = (-1) * 10 ** 9 for i in range(2 ** 10): if sum(map(int, list(str(i)))) == 0: continue cnt_lst = [...
def main(): from itertools import combinations N = int(eval(input())) F = [] for _ in range(N): t = 0 for j, b in enumerate(map(int, input().split())): if b: t |= (1 << j) F.append(t) # F[i]:=店舗iの営業時間情報 P = [list(map(int, input().s...
p03503
#!/mnt/c/Users/moiki/bash/env/bin/python # N,M = map(int, input().split()) N = int(eval(input())) F = [list(map(int, input().split())) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] ans = - 10**10 for i in range(1,1<<10): score = 0 for n in range(N): f = "".join(...
N = int(eval(input())) F = [ int(input().replace(" ", ""), 2) for _ in range(N)] P = [list(map(int, input().split())) for _ in range(N)] ans = - 10**10 for i in range(1,1<<10): ans = max(ans, sum(P[n][bin(i&F[n]).count('1')] for n in range(N))) print(ans)
p03503
icase=0 if icase==0: n=int(eval(input())) f=[] for i in range(n): fi=list(map(int,input().split())) f.append(fi) p=[] for i in range(n): pi=list(map(int,input().split())) p.append(pi) elif icase==1: n=1 f=[[1, 1, 0, 1, 0, 0, 0, 1, 0, 1]] p...
import itertools n=int(eval(input())) f=[[]]*n for i in range(n): fij=list(map(int,input().split())) # f[i].append(fij) f[i]=fij p=[[]]*n for i in range(n): pij=list(map(int,input().split())) p[i]=pij pmax=-10**11 for a in itertools.product([0,1], repeat=10): if sum(a)==0: ...
p03503
# -*- coding: utf-8 -*- import itertools N = int(eval(input())) F = [] for i in range(N): F.append(list(map(int, input().split()))) P = [] for i in range(N): P.append(list(map(int, input().split()))) # 重複順列で自分の店の全パターンを出す me_list = list(itertools.product([0, 1], repeat=10)) # 初期値は利益の最小値 me_p ...
# -*- coding: utf-8 -*- import itertools N = int(eval(input())) F = [] for i in range(N): F.append(list(map(int, input().split()))) P = [] for i in range(N): P.append(list(map(int, input().split()))) # 重複順列で自分の店の全パターンを出す me_list = list(itertools.product([0, 1], repeat=10)) # 初期値は利益の最小値 me_p ...
p03503
import itertools mylist = [0, 1] n = int(input().rstrip()) mise = [list(map(int, input().rstrip().split())) for i in range(n)] mine = [list(map(int, input().rstrip().split())) for i in range(n)] maxnum = - float('inf') for i in itertools.product(mylist, repeat = 10): if sum(i) == 0: continue ...
MAX_TIME = 10 n = int(input().rstrip()) #2進法を P = [sum(int(i) << MAX_TIME-k-1 for k, i in enumerate(input().rstrip().split())) for j in range(n)] S = [list(map(int, input().rstrip().split())) for i in range(n)] #予め2進数をカウントしておく # 予めビットをカウントしておく pattern = [sum(i >> j & 1 for j in range(MAX_TIME)) for i in rang...
p03503
N = int(eval(input())) F = [list(map(int, input().split())) for k in range(N)] P = [list(map(int, input().split())) for k in range(N)] B = [format(k,'b').zfill(10) for k in range(1,1024)] ans = -10**9 for d in B: t = 0 E = [0 for k in range(N)] for l in range(N): for k in range(10): ...
N = int(eval(input())) F = [list(map(int,input().split())) for k in range(N)] P = [list(map(int,input().split())) for k in range(N)] ans = -float("inf") for k in range(2**10): temp = 0 S = [0 for l in range(N)] for s in range(N): for d in range(10): if (k>>d)&1 == 1: ...
p03503
import itertools N=eval(input()) F=[] for i in range(N): F.append(list(map(int,input().split()))) #print F P=[] for i in range(N): P.append(list(map(int,input().split()))) #print P l=list(itertools.product(list(range(2)), repeat=10)) #l=[(1, 1, 1, 1, 1, 0, 0, 0, 0, 0),(0, 0, 0, 0, 0, 1, 1, 1, 1, 1),(...
# -*- coding: utf-8 -*- import sys N=eval(input()) F=[ list(map(int, sys.stdin.readline().split())) for _ in range(N)] P=[ list(map(int, sys.stdin.readline().split())) for _ in range(N)] D=[] #各店の状態を10進数で表示 for f in F: #各店の状態を10進数に置き換え n=0 for i,x in enumerate(f): if x==1: n...
p03503
N=int(eval(input())) F=[int(input().replace(' ',''),2)for _ in[0]*N] P=[list(map(int,input().split()))for _ in[0]*N] ans = -float('inf') for i in range(1,2**10): sum = 0 for k in range(N): sum += P[k][bin(F[k]&i).count('1')] if ans < sum: ans = sum print(ans)
N=int(eval(input())) F=[int(input().replace(' ',''),2)for _ in[0]*N] P=[list(map(int,input().split()))for _ in[0]*N] print((max(sum([p[bin(f&i).count('1')]for f,p in zip(F,P)])for i in range(1,2**10))))
p03503