Problem:


Score : 400 points

Problem Statement

One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N.
He is interested in properties of the sequence a.

For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its beauty is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.)

Find the maximum possible value for him.

Constraints

2 \leq N \leq 1000

1 \leq a_i \leq 10^9

1 \leq K \leq N(N+1)/2

All numbers given in input are integers

Input

Input is given from Standard Input in the following format:

N K
a_1 a_2 ... a_N

Output

Print the answer.

Sample Input 1

4 2
2 5 2 5

Sample Output 1

12

There are 10 nonempty contiguous subsequences of a. Let us enumerate them:

contiguous subsequences starting from the first element: \{2\}, \{2, 5\}, \{2, 5, 2\}, \{2, 5, 2, 5\}

contiguous subsequences starting from the second element: \{5\}, \{5, 2\}, \{5, 2, 5\}

contiguous subsequences starting from the third element: \{2\}, \{2, 5\}

contiguous subsequences starting from the fourth element: \{5\}

(Note that even if the elements of subsequences are equal, subsequences that have different starting indices are considered to be different.)

The maximum possible bitwise AND of the beauties of two different contiguous subsequences is 12.
This can be achieved by choosing \{5, 2, 5\} (with beauty 12) and \{2, 5, 2, 5\} (with beauty 14).

Sample Input 2

8 4
9 1 8 2 7 5 6 4

Sample Output 2

32



Sample input:
4 2
2 5 2 5


Sample output:
12

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = len(b)

res = 0
for i in range(41):
    p = res + (1 << (40-i))
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = len(b)

res = 0
for i in range(51):
    p = res + (1 << (50-i))
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=[]
for i in range(n):
    for j in range(i+1,n):
        a=0
        a+=sum(l[i:j+1])
        s.append(a)
s.sort(reverse=True)
#print(s)
m=40
x=0
for i in range(40,-1,-1):
    a=0
    for j in s:
        if (x+2**i)&j==(x+2**i):
            a+=1
           # print(i,j)
        if a>=k:
            x+=2**i
            break
print(x)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
l=list(map(int,input().split()))
s=[]
for i in range(n):
    for j in range(i+1,n):
        a=0
        a+=sum(l[i:j+1])
        s.append(a)
s.sort(reverse=True)
#print(s)
m=40
x=0
for i in range(40,-1,-1):
    a=0
    for j in s:
        if (x+2**i)&j==(x+2**i):
            a+=1
           # print(i,j)
    if a>=k:
        x+=2**i
print(x)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

from itertools import combinations

n, k = map(int, input().split())
an = [a for a in map(int, input().split())]

bn = [sum(an[i:y+1]) for y in range(n) for i in range(n)]

xmax = 0
m = 40
for i in range(m, 0, -1):
    counter = 0
    for b in bn:
        t = xmax + pow(2, i)
        if t&b == t:
            counter += 1
            if counter >= k:
                xmax += pow(2, i)
                break
    
print(xmax)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

from itertools import combinations

n, k = map(int, input().split())
an = [a for a in map(int, input().split())]

bn = []
for i in range(n):
    for y in range(n):
        bn.append(sum(an[i:y+1]))

xmax = 0
m = 40
for i in range(m, 0, -1):
    counter = 0
    for b in bn:
        t = xmax + pow(2, i)
        if t&b == t:
            counter += 1
            if counter >= k:
                xmax += pow(2, i)
                break
    
print(xmax)

Submission status: Time Limit Exceeded

Solution code:
# coding:utf-8

from itertools import combinations

n, k = map(int, input().split())
an = [a for a in map(int, input().split())]

bn = []
for i in range(n):
    for y in range(n):
        bn.append(sum(an[i:y+1]))

xmax = 0
m = 40
for i in range(m, 0, -1):
    counter = 0
    for b in bn:
        t = xmax + pow(2, i)
        if t&b == t:
            counter += 1
    if counter >= k:
        xmax += pow(2, i)
    
print(xmax)

Submission status: Time Limit Exceeded

Solution code:
from math import log2
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [[a[i]] for i in range(n)]
c = list(a)

for i in range(n-1):
    for j in range(i+1, n):
        b[i].append(a[j]+b[i][-1])
        c.append(b[i][-1])

m = 40 #ceil(log2((10**9)*1000))=40よりbit幅を40としておけば十分
ans = 0
for i in range(m, 0, -1):
    count = 0
    for p in c:
        if (ans + 2**(i-1)) & p == ans + 2**(i-1):
            count += 1
            if count == k:
                ans += 2**(i-1)
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))

cond = []
for i in range(len(a)):
    for j in range(i, len(a)):
        cond.append(sum(a[i:j+1]))

ans = 0
for i in reversed(range(40)):
    b = ans + 2**i
    cnt = 0
    for c in cond:
        if c&b==b:
            cnt += 1
    if cnt>=K:
        ans = b

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
a = list(map(int, input().split()))

cond = []
for i in range(len(a)):
    for j in range(i, len(a)):
        cond.append(sum(a[i:j+1]))

ans = 0
for i in reversed(range(40)):
    b = ans + 2**i
    cnt = 0
    for c in cond:
        if c&b==b:
            cnt += 1
    if cnt>=K:
        ans = b

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = []
m = 0
x = 0
for l in range(N):
  for r in range(l,N):
    b.append(sum(a[l:r+1]))
while(2**m<max(b)):
  m+=1
for t in reversed(range(1,m+1)):
  count = 0
  for i in range(len(b)):
    if (2**t + x)&b[i] ==(2**t + x):
      count+=1
  if count >= K:
    x = x+2**t
print(x)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = []
m = 40
x = 0
for l in range(N):
  for r in range(l,N):
    b.append(sum(a[l:r+1]))
for t in reversed(range(1,m+1)):
  count = 0
  for i in range(len(b)):
    if (2**t + x)&b[i] ==(2**t + x):
      count+=1
  if count >= K:
    x = x+2**t
print(x)

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
a = list(map(int,input().split()))
b = []
bi = 2**39
max = 0
for l in range(N):
  for r in range(l,N):
    b.append(sum(a[l:r+1]))
b.sort()

while(bi>=1):
  List = []
  for i in range(len(b)):
    if int(bi)&b[i]>0:
      List.append(b[i])
  if len(List)>=K:
    b = List
    max += bi
  bi = bi/2

print(int(max))

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
d=list(map(int,input().split()))

ds = []
 
for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

ds.sort(reverse=True)
 
for i in range(40,-1,-1):
    count = 0
    o = []
 
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
    if count >= k :
        ds = list(o)
  
sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = str(input())
lines = line.split(' ')
 
n = int(lines[0])
k = int(lines[1])
 
d = list()
 
line = str(input())
lines = line.split(' ')
 
for l in lines:
    d.append(int(l))
 
ds = list()
 
for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

ds.sort(reverse=True)
 
for i in range(40,-1,-1):
    count = 0
    o = []
 
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
    if count >= k :
        ds = list(o)
  
sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = str(input())
lines = line.split(' ')
 
n = int(lines[0])
k = int(lines[1])
 
d = list()
 
line = str(input())
lines = line.split(' ')
 
for l in lines:
    d.append(int(l))
 
ds = list()
 
for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)
 
for i in range(40,-1,-1):
    count = 0
    o = []
 
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
    if count >= k :
        ds = list(o)
  
sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]
 
print(sum)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())
a = list(map(int, input().split()))
beautiful_num = []

for i in range(N):
    temp = 0
    for n in a[i:]:
        temp += n
        beautiful_num.append("{:040b}".format(temp))

ma_b_cnt = 0
target_set = None

for i in range(40):
    if target_set is None:
        for b in beautiful_num:
            if b[i] == "1":
                ma_b_cnt += 1
        if ma_b_cnt < K:
            ma_b_cnt = 0
        else:
            target_set = set([b for b in beautiful_num if b[i] == "1"])
    else:
        count = 0
        for b in target_set:
            if b[i] == 0:
                count += 1
        if len(target_set) - count >= K:
            for b in target_set:
                if b[i] == 0:
                    target_set.remove(b)
        else:
            break

result = 0
for comb in itertools.combinations(target_set, K):
    temp = bin(int(comb[0], 2))
    for b in comb:
        temp = bin(int(b, 2) & int(temp, 2))
    temp = int(temp, 2)
    if temp > result:
        result = temp

print(result)

Submission status: Time Limit Exceeded

Solution code:
line = str(input())
lines = line.split(' ')

n = int(lines[0])
k = int(lines[1])

d = list()

line = str(input())
lines = line.split(' ')

for l in lines:
    d.append(int(l))

ds = list()

for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

digit = 0
o = list()

for i in range(40,-1,-1):
    count = 0
    o.clear()

    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        ds = o.copy()

    if count == k :
        break

sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]

print(sum)

Submission status: Time Limit Exceeded

Solution code:
line = str(input())
lines = line.split(' ')

n = int(lines[0])
k = int(lines[1])

d = list()

line = str(input())
lines = line.split(' ')

for l in lines:
    d.append(int(l))

ds = list()

for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

digit = 0
o = list()

for i in range(40,-1,-1):
    count = 0
    o.clear()

    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)

    if count >= k :
        ds = o.copy()

sum = ds[0]
for i in range(1,k):
    sum = sum & ds[i]

print(sum)

Submission status: Time Limit Exceeded

Solution code:

N, K = map(int, input().split())
a = [int(x) for x in input().split()]

beautifuls = []
for i in range(0, len(a)):
    for j in range(i+1, len(a)+1):
        beautiful = sum(a[i:j])
        beautifuls.append(beautiful)

x_ = 0
t = 40
count = 0
while 1:
    for i in range(len(beautifuls)):
        if eval(str(bin((x_ + 2**(t-1)) & beautifuls[i]))) == x_+ 2**(t-1):
            count += 1
            if count == K:
                x_ += 2**(t-1)
                t = 40
                break
    count = 0
    t -= 1
    if t == 0:
        break

print(x_)

Submission status: Time Limit Exceeded

Solution code:

N, K = map(int, input().split())
a = [int(x) for x in input().split()]

beautifuls = []
for i in range(0, len(a)):
    for j in range(i+1, len(a)+1):
        beautiful = sum(a[i:j])
        beautifuls.append(beautiful)

x_ = 0
t = 1
count = 0
while 1:
    for i in range(len(beautifuls)):
        if eval(str(bin((x_ + 2**(t-1)) & beautifuls[i]))) == x_+ 2**(t-1):
            count += 1
            if count == K:
                x_ += 2**(t-1)
                t = 0
                break
    count = 0
    t += 1
    if t > 40:
        break

print(x_)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())
a = list(map(int, input().split()))
beautiful_num = []
bit_mask = []

for i in range(N):
    for j in range(N):
        if i <= j:
            temp = [0] * N
            for k in range(i, j+1):
                temp[k] = 1
            bit_mask.append(temp)

for bit in bit_mask:
    temp = 0
    for b, num in zip(bit, a):
        if b == 1:
            temp += num
    beautiful_num.append("{:040b}".format(temp))

ma_b_cnt = 0
target_set = None

for i in range(40):
    if target_set is None:
        for b in beautiful_num:
            if b[i] == "1":
                ma_b_cnt += 1
        if ma_b_cnt < K:
            ma_b_cnt = 0
        else:
            target_set = set([b for b in beautiful_num if b[i] == "1"])
    else:
        count = 0
        for b in target_set:
            if b[i] == 0:
                count += 1
        if len(target_set) - count >= K:
            for b in target_set:
                if b[i] == 0:
                    target_set.remove(b)
        else:
            break

result = 0
for comb in itertools.combinations(target_set, K):
    temp = bin(int(comb[0], 2))
    for b in comb:
        temp = bin(int(b, 2) & int(temp, 2))
    temp = int(temp, 2)
    if temp > result:
        result = temp

print(result)

Submission status: Time Limit Exceeded

Solution code:
import itertools

line = str(input())
lines = line.split(' ')

n = int(lines[0])
k = int(lines[1])

d = list()

line = str(input())
lines = line.split(' ')

for l in lines:
    d.append(int(l))

ds = list()

for i in range(0,n):
    for len in range(1,n-i+1):
        sum = 0
        for j in range(i,i+len):
            sum += d[j]
        ds.append(sum)

digit = 0
o = list()

for i in range(31,-1,-1):
    count = 0
    o.clear()
    for dss in ds:
        if dss & (1 << i) > 0 :
            count += 1
            o.append(dss)
    if count >= k :
        digit = i
        break

ls = list(itertools.combinations(o,k))

max = 0
for t in ls:
    sum = t[0]

    for u in t:
        sum = sum & u

    if sum > max : 
        max = sum

print(max)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())

c = [int(_) for _ in input().split()]

l = []
for i in range(a):
    l += [c[i]]
    for j in range(i+1,a):
        l += [l[-1] + c[j]]
co = 0
la = 0
for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (la + 2 ** i) == (la + 2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)

Submission status: Time Limit Exceeded

Solution code:
n, k = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]

b = []
for i in range(n):
    s = a[i]
    b.append(s)
    for j in range(i+1, n):
        s += a[j]
        b.append(s)

MAX = 40
ans = 0
for t in range(MAX, 0, -1):
    x = ans + 2 ** (t-1)
    cnt = 0
    for v in b:
        if x & v == x:
            cnt += 1
    if cnt >= k:
        ans = x

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())

c = list(map(int,input().split()))

l = []
for i in range(a):
    l += [c[i]]
    for j in range(i+1,a):
        l += [l[-1] + c[j]]
co = 0
la = 0
for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (la + 2 ** i) == (la + 2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())

c = list(map(int,input().split()))

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])
co = 0
la = 0
for i in range(40,-1,-1):
	q = 2 ** i
	for j in range(len(l)):
		if l[j] & (la + q) == (la + q):
			co += 1
	if co >= b:
		la += q
	co = 0

print(la)

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split())

c = list(map(int,input().split()))

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])
co = 0
la = 0
for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (la + 2 ** i) == (la + 2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = [a[0]]
for i in range(n-1):
    b.append(b[i]+a[i+1])
c1 = list(itertools.combinations(range(n),2))
s = a
for i in c1:
    s.append(b[i[1]]-b[i[0]]+a[i[0]])
c2 = list(itertools.combinations(range(len(s)),k))
max=0
for i in c2:
    t = s[i[0]]
    for j in i:
        t = t&s[j]
    if max < t:
        max = t
print(max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = np.sort(np.array([sum(A[j:j+N-i]) for i in range(N) for j in range(i+1)]))[::-1]
ans = sumlist[0]
for i in range(40, -1, -1):
    tmp = (ans & (2 ** i)) // (2 ** i)
    if tmp:
        start = i
        break
f = lambda x: (x & onehot) // onehot
ans_list = [0]
ans = 0
for i in range(start, -1, -1):
    onehot = 2 ** i + ans
    tmp = list(map(f, sumlist))
    if sum(tmp) >= K:
        and_result = np.array(tmp).astype(np.bool)
        sumlist = sumlist[and_result]
        ans = onehot
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = np.sort(np.array([sum(A[j:j+N-i]) for i in range(N) for j in range(i+1)]))[::-1]
ans = sumlist[0]
for i in range(40, -1, -1):
    tmp = (ans & (2 ** i)) // (2 ** i)
    if tmp:
        start = i
        break
f = lambda x: (x & onehot) // onehot
ans_list = [0]
ans = 0
for i in range(start, -1, -1):
    onehot = 2 ** i + ans
    tmp = list(map(f, sumlist))
    if sum(tmp) >= K:
        ans = onehot
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
A=np.array(A).cumsum()

Y=[]
for i in range(N):
    for j in range(i+1,N+1):
        Y.append(A[j]-A[i])
    
answer=0
p=40
while p>=0:
    x=answer+2**p
    ans=0
    for y in Y:
        if x&y == x: ans+=1
    if ans>=K:
        answer=x
    p-=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = inpl()
tmp = 0
S = [0]*N
Q = []
for i in range(N):
    tmp += A[i]
    S[i] = tmp
    Q.append(tmp)

tmp = 0
for i in range(1, N):
    tmp = S[i-1]
    for j in range(i, N):
        #print(i, j)
        v = S[j] -S[i-1]
        Q.append(v)

res = 0
L = len(Q)
I = len(bin(sum(A))) - 2
while True:
    ok = 0
    for i in range(I):
        num = res + 2**i
        tmp = 0
        for j in range(L):
            if num & Q[j] == num:
                tmp += 1
        if tmp >= K:
            ok = num

    I = len(bin(res - ok)) - 2
    if res < ok & ok > 0:
        res = ok
    else:
        break

print(res)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
A=np.array(A).cumsum()
    
answer=0
p=40
while p>=0:
    x=answer+2**p
    ans=0
    for i in range(N):
        for j in range(i+1,N+1):
            y=A[j]-A[i]
            if x&y == x: ans+=1
    if ans>=K:
        answer=x
    p-=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
acc = [0]
for a in A:
    acc.append(acc[-1] + a)
B = []
for i in range(N):
    for j in range(i + 1, N + 1):
        B.append(acc[j] - acc[i])
B.sort()
count_dict = dict()
for b in B:
    count_dict[b] = count_dict.get(b, 0) + 1
ans = 0
for i in reversed(range(40)):
    bit = 1 << i
    if sum(v for k, v in count_dict.items() if ((ans + bit) & k) == ans + bit) >= K:
        ans += bit
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

s = 0
ma = 0
for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])
    ma = max(ma, max(C))

IDX = 0
while ((1 << IDX) < ma):
    IDX += 1


def filterList(list, i):
    retList = []
    for l in list:
        if l & (1 << i):
            retList.append(l)
    return retList

D = C
for i in range(IDX,-1,-1):
    newD = filterList(D,i)
    if len(newD) < K:
        break
    else:
        D = newD


EE = list(itertools.combinations(D, K))
EE = list(set(EE))

ret = 0
for E in EE:
    r = E[0]
    for e in E:
        r = r & e
    ret = max(ret, r)


print(ret)

sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

s = 0
ma = 0
for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])
    ma = max(ma, max(C))

IDX = 0
while ((1 << IDX) < ma):
    IDX += 1


def filterList(list, i):
    retList = []
    for l in list:
        if l & (1 << i):
            retList.append(l)
    return retList

D = C
for i in range(IDX,-1,-1):
    newD = filterList(D,i)
    if len(newD) < K:
        break
    else:
        D = newD


EE = list(itertools.combinations(D, K))

ret = 0
for E in EE:
    r = E[0]
    for e in E:
        r = r & e
    ret = max(ret, r)


print(ret)

sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = [int(s) for s in input().split()]

ru = [None] * (N+1)
ru[0] = 0
for i in range(len(A)):
    ru[i+1] = ru[i] + A[i]

ans = 0
for m in reversed(range(40)):
    cnt = 0
    for i in range(N):
        for j in range(i+1, N+1):
            sum = ru[j] - ru[i]
            if (sum & ans) < ans:
                continue
            if sum & (1 << m):
                cnt += 1
    if cnt >= K:
        ans |= (1 << m)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = np.sort(np.array([sum(A[j:j+N-i]) for i in range(N) for j in range(i+1)]))[::-1]
ans = sumlist[0]
for i in range(40, -1, -1):
    tmp = (ans & (2 ** i)) // (2 ** i)
    if tmp:
        start = i
        break
f = lambda x: (x & onehot) // onehot
ans_list = [0]
for i in range(start, -1, -1):
    onehot = 2 ** i
    tmp = list(map(f, sumlist))
    if sum(tmp) >= K:
        and_result = np.array(tmp).astype(np.bool)
        sumlist = sumlist[and_result]
        ans = sumlist[0]
        for j in range(1, K):
            ans = ans & sumlist[j]
        ans_list.append(ans)
print(max(ans_list))

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import itertools
import math
import re
from collections import Counter
from collections import deque
from collections import defaultdict

MOD = 10 ** 9 + 7

N,K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

C = []

s = 0
ma = 0
for i in range(0,N-1):
    for j in range(i, N):
        if j==i:
            C.append(A[i])
        else:
            C.append(C[-1] + A[j])
    ma = max(ma, max(C))

IDX = 0
while ((1 << IDX) < ma):
    IDX += 1


def filterList(list, i):
    retList = []
    cnt = 0
    for l in list:
        if l & (1 << i):
            cnt += 1
            retList.append(l)

    if cnt >= K:
        return retList
    else:
        return list



# 31..0
D = C
for i in range(IDX,-1,-1):
    D = filterList(D,i)


EE = list(itertools.combinations(D, K))

ret = 0
for E in EE:
    r = E[0]
    for e in E:
        r = r & e
    ret = max(ret, r)


print(ret)

sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(temp)
    if len(ls_target)>=k*8:
    #if i==n:
        break
    i+=1

def check(num):
    for i in range(100):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = sum(ls_target[0])
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if sum(ls) & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = [sum(A[j:j+N-i]) for i in range(N) for j in range(i+1)]
sumlist.sort(reverse=True)
sumlist = np.array(sumlist)
ans = sumlist[0]
for i in range(40, -1, -1):
    tmp = (ans & (2 ** i)) // (2 ** i)
    if tmp:
        start = i
        break
f = lambda x: (x & onehot) // onehot
ans_list = [0]
for i in range(start, -1, -1):
    onehot = 2 ** i
    tmp = list(map(f, sumlist))
    if sum(tmp) >= K:
        and_result = np.array(tmp).astype(np.bool)
        sumlist = sumlist[and_result]
        ans = sumlist[0]
        for j in range(1, K):
            ans = ans & sumlist[j]
        ans_list.append(ans)
print(max(ans_list))

Submission status: Time Limit Exceeded

Solution code:
def show(target):
    for i in range(len(target)):
        print(bin(target[i])[2:].zfill(8))
    print("len:{}".format(len(target)))


n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

# ありうる部分数列を列挙
beauty = []
for i in range(n):
    for j in range(i + 1, n + 1):
        beauty.append(sum(a[i:j]))
beauty = sorted(beauty)
target = [beauty[0]]
for i in range(1, len(beauty)):
    if beauty[i] != beauty[i - 1]:
        target.append(beauty[i])
digit = 0
# print(target)
targetDigit = target[-1]
while targetDigit > 0:
    digit += 1
    targetDigit = int(targetDigit / 2)
out = 0
while digit > 0:
    target = list(reversed(sorted(target)))
    # print(digit)
    # show(target)
    count = 0
    for i in range(len(target)):
        if target[i] >> (digit - 1) == 1:
            count += 1
    if count >= k:
        out += 2 ** (digit - 1)
        i = count
        while i < len(target):
            del (target[i])
            
    i = 0
    while i < len(target):
        target[i] &= (1 << (digit - 1)) - 1
        if target[i] == 0:
            del (target[i])
        else:
            i += 1
    digit -= 1
    # print("out:{}".format(out))
print(out)
"""
8 4
1 1 1 1 1 1 1 1 
"""

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N,K=map(int,input().split())
A=list(map(int,input().split()))
A.insert(0,0)
A=np.array(A).cumsum()

a=A[-1]
n=1
while True:
    a=a/2
    if a<1: break
    n+=1
    
answer=0
p=n-1
while p>=0:
    x=answer+2**p
    ans=0
    for i in range(N):
        for j in range(i+1,N+1):
            y=A[j]-A[i]
            if x&y == x: ans+=1
    if ans>=K:
        answer=x
    p-=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
# def to_2(num):
#     ret = []
#     while (num != 0):
#         if num % 2 == 1:
#             ret.append(True)
#         else:
#             ret.append(False)
#         num = num // 2
#     return np.array(ret)

# def()

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

# 全探索
from itertools import combinations
A_2 = [bin(a) for a in A]

kouho = [sum(A[idx:(idx2+1)]) for idx, idx2 in combinations(range(0, N), 2)]


ma = 0
for A_sub in combinations(kouho, K):
    bina = A_sub[0]
    # print(bina)
    for i in range(1, K):
        bina = bina & A_sub[i]
    if bina > ma:
        ma = bina

print(ma)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


N, K = list(map(int, input().split()))
A    = list(map(int, input().split()))

L = []

for l in range(N):
    for k in range(N+1):
        if l < k:
            L.append(sum(A[l:k]))

L.sort()
L = L[::-1]

L = [format(l, 'b') for l in L]
k = len(L[0])
L = [('0' * (k - len(l))) + l for l in L]
L = [list(map(int, list(l))) for l in L]

L.sort()
L = L[::-1]
L = np.array(L)

for i in range(k):
    if np.sum(L[:, i]) >= K:
        L = L[L[:, i] == 1]

L = L[:K]

R = '0b'

for i in range(k):
    if 0 in L[:, i].tolist():
        R += '0'
    else:
        R += '1'

print(int(R, 2))

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(temp)
    if len(ls_target)>=k*10:
    #if i==n:
        break
    i+=1

def check(num):
    for i in range(100):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = sum(ls_target[0])
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if sum(ls) & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, K = map(int, input().split())
A = list(map(int, input().split()))
sumlist = [sum(A[j:j+N-i]) for i in range(N) for j in range(i+1)]
sumlist.sort(reverse=True)
sumlist = np.array(sumlist)
ans = sumlist[0]
for i in range(40, -1, -1):
    tmp = (ans & (2 ** i)) // (2 ** i)
    if tmp:
        start = i
        break
f = lambda x: (x & onehot) // onehot
ans_list = [0]
for i in range(start, -1, -1):
    onehot = 2 ** i
    tmp = sum(map(f, sumlist))
    if tmp >= K:
        and_result = list(map(f, sumlist))
        and_result = np.array(and_result).astype(np.bool)
        sumlist = sumlist[and_result]
        ans = sumlist[0]
        for j in range(1, K):
            ans = ans & sumlist[j]
        ans_list.append(ans)
print(max(ans_list))