description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
self.res = set()
def helper(idx):
if idx < 0:
return set()
if idx == 0:
self.res |= {A[idx]}
return {A[idx]}
val = {A[idx]} | {(x | A[idx]) for x i... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER VAR VAR VAR RETURN VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, a: List[int]) -> int:
res, prev = set(), set()
res.add(a[0])
prev.add(a[0])
for i in range(1, len(a)):
cur = set()
cur.add(a[i])
res.add(a[i])
for j in prev:
cur.add(j | a[i]... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL... |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
res = set([])
tmp = set([])
for i in A:
newtmp = set([])
for j in tmp:
newtmp.add(i | j)
res.add(i | j)
newtmp.add(i)
res.add(i)
tmp... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
my_set = [set([A[i]]) for i in range(len(A))]
for i in range(1, len(A)):
for prev_result in my_set[i - 1]:
my_set[i].add(A[i] | prev_result)
return len(set.union(*my_set)) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
mp = {(0): 1}
ans = {}
for a in A:
temp = {}
for m in mp:
temp[m | a] = 1
temp[a] = 1
for t in temp:
ans[t] = 1
mp = {}
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER RETURN VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
res = []
left, right = 0, 0
for val in A:
right = len(res)
res.append(val)
for i in range(left, right):
if res[-1] != res[i] | val:
res.append(res[i] | ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
result_set = set()
results = set()
for num in A:
results = {(j | num) for j in results}
results.add(num)
result_set.update(results)
return len(result_set) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, arr: List[int]) -> int:
s = set()
prev = set()
prev.add(arr[0])
s.add(arr[0])
for i in range(len(arr)):
temp = set()
for val in prev:
temp.add(val | arr[i])
s.add(val | arr[i... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL ... |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
vals = set()
if len(A) < 2:
return len(A)
cur = {0}
for a in A:
cur = {(a | y) for y in cur} | {a}
vals |= cur
return len(vals) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
ans, dp = set(), set()
for x in A:
ndp = set()
ndp.add(x)
for y in dp:
ndp.add(x | y)
ans.add(y)
dp = ndp
for x in dp:
ans.add(x)
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
sets = [{i} for i in A]
for i in range(1, len(A)):
for prev in sets[i - 1]:
sets[i].add(A[i] | prev)
return len(set.union(*sets)) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
n = len(A)
dp = set()
ans = set()
for j in range(n):
dp_new = set()
dp_new.add(A[j])
for x in dp:
dp_new.add(x | A[j])
dp = dp_new
ans.updat... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
ans = set()
prev = set()
prev.add(0)
for i in range(len(A)):
cur = set()
cur.add(A[i])
for p in prev:
res = p | A[i]
if res != p:
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR... |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
dp = []
for i in range(len(A)):
if i == 0:
dp.append(set([A[i]]))
else:
inner = set([A[i]])
for d in dp[-1]:
inner.add(d | A[i])
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR... |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
S, prev = set(), set()
for a in A:
temp = set()
temp.add(a)
S.add(a)
for p in prev:
temp.add(a | p)
S.add(a | p)
prev = temp
return ... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
if not A:
return []
for i in range(len(A))[::-1]:
if i > 0 and A[i] == A[i - 1]:
A.pop(i)
all_outcomes = set([A[0]])
outcomes = set([A[0]])
for elt in A[1:]:
... | CLASS_DEF FUNC_DEF VAR VAR IF VAR RETURN LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN... |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A):
nums, n, pre = set(), len(A), set()
for a in A:
pre = {a} | {(num | a) for num in pre}
nums |= pre
return len(nums) | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
sets = [{i} for i in A]
for i in range(1, len(A)):
for prev in sets[i - 1]:
sets[i].add(A[i] | prev)
for num in sets[1:]:
sets[0] |= num
return len(sets[0]) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FOR VAR VAR NUMBER VAR NUMBER VAR RETURN FUNC_CALL VAR VAR NUMBER VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
prev = set()
curr = set()
vals = set(A)
for x in A:
curr.add(x)
for y in prev:
curr.add(x | y)
vals.add(x | y)
prev = curr
curr = set()
... | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
alive = set()
dead = set()
for num1 in A:
tmp = {num1}
for num2 in alive:
dead.add(num2)
tmp.add(num1 | num2)
alive = tmp
return len(alive | dead) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
s = set()
global_set = set()
ans = 0
for v in A:
s.add(v)
s = {(x | v) for x in s}
global_set |= s
return len(global_set) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR |
We have an array A of non-negative integers.
For every (contiguous) subarray B = [A[i], A[i+1], ..., A[j]] (with i <= j), we take the bitwise OR of all the elements in B, obtaining a result A[i] | A[i+1] | ... | A[j].
Return the number of possible results. (Results that occur more than once are only counted once in th... | class Solution:
def subarrayBitwiseORs(self, A: List[int]) -> int:
S, last = set(), set()
for i in range(len(A)):
last = {(a | A[i]) for a in last}
last.add(A[i])
S |= last
return len(S) | CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Nobody outside the cooking community knows that Chef is a big fan of Chefgram™ — a social network where chefs and cooks upload their secret kitchen photos.
Recently Chef clicked a beautiful photo, which is represented using 10 pixels in a s... | mod = 10**9 + 7
N = 10**5
p2 = [1] * (N + 1)
for i in range(N):
p2[i + 1] = (p2[i] << 1) % mod
def getmask(s):
ans = 0
mask = 1
for i in range(9, -1, -1):
if s[i] == "w" or s[i] == "+":
ans |= mask
mask = mask << 1
return ans
val = 1 << 10
for _ in range(int(input()))... | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ... |
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Nobody outside the cooking community knows that Chef is a big fan of Chefgram™ — a social network where chefs and cooks upload their secret kitchen photos.
Recently Chef clicked a beautiful photo, which is represented using 10 pixels in a s... | fs = "bbbbbbbbbb"
MOD = 1000000007
par = [512, 256, 128, 64, 32, 16, 8, 4, 2, 1]
for _ in range(0, int(input())):
s = str(input())
ts = ""
for i in range(0, len(s)):
if s[i] != fs[i]:
ts = ts + "1"
else:
ts = ts + "0"
t = int(input())
f = [0] * t
inb = [0]... | ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR BIN_OP ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
for _ in range(t):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
max_ele = max(A)
max_len = len(bin(max_ele)) - 2
buckets = {}
for j in range(1, max_len + 1):
buckets[j] = []
for a in A:
l = len(bin(a)) - 2
buckets[l].appe... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CA... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
for _ in range(t):
n, k = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
dp = []
for i in range(n):
dp.append([])
for j in range(1024):
dp[i].append(0)
dp[0][0] = 1
dp[0][a[0]] = 1
for i in range(1, n):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR NUMBER EX... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for i in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
dp = [[(0) for i in range(1024)] for j in range(1024)]
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1024):
dp[i][j] = dp[i - 1][j] | dp[i - 1][j ^ l[i - 1]]
print(max([... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
for T in range(t):
s = []
e = []
s = list(map(int, input().split()))
e = list(map(int, input().split()))
dp = [False] * 1024
dp[0] = True
for i in e:
for x in range(int(1024)):
if dp[x]:
dp[x ^ i] = True
ans = 0
for i in range(1024... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CA... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
dp = [([0] * 1024) for i in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1024):
if dp[i - 1][j] == 1:
dp[i][j] = 1
d... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().split())
l = [int(i) for i in input().split()]
dp = [0] * 1024
dp[0] = 1
for i in range(n):
for j in range(1024):
dp[j ^ l[i]] = dp[j] | dp[j ^ l[i]]
maxi = 0
for i in range(1024):
if dp[i]:
maxi = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VA... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ad = set(arr)
w = [k]
ans = k
v = set()
v.add(k)
for i in ad:
for j in range(len(w)):
x = w[j] ^ i
ans = max(ans, x)
v.add(x)
w = list(... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
for i in range(t):
N, K = map(int, input().split())
A = list(map(int, input().split()))
n = 1023
dp = [0] * (n + 1)
dp[0] = 1
for i in range(N):
for j in range(n + 1):
x = j ^ A[i]
if dp[j] == 1:
dp[x] = 1
Max = 0
for i in ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_C... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | __author__ = "Ronald Kaiser"
__email__ = "raios dot catodicos at gmail dot com"
def solve(A, K):
m, n = len(A), 2 ** len(bin(max(max(A), K))[2:])
dp = [[(False) for _ in range(n)] for _ in range(m)]
dp[0][0] = True
maxi = 0
for i in range(1, m):
for j in range(n):
dp[i][j] = dp... | ASSIGN VAR STRING ASSIGN VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().strip().split())
S = list(map(int, input().strip().split()))
dp = [(0) for i in range(1024)]
dp[0] = True
for i in range(n):
for j in range(1024):
dp[j ^ S[i]] |= dp[j]
ans = k
for i in range(1024):
if dp[i]:
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input().strip())):
n, k = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
Matrix = [[(0) for x in range(1024)] for y in range(n + 1)]
for i in lst:
Matrix[1][i] = 1
for i in range(2, n + 1):
for j in range(1024):
if Matri... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER VAR NUM... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | def solve():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
ans = {0}
for i in range(n):
temp = {0}
for j in ans:
temp.update({arr[i] ^ j})
temp.update({arr[i]})
ans.update(temp)
ans_1 = 0
ans = list(ans)
for m in ans:
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().split())
l = [int(i) for i in input().split()]
ans = k
s = {k}
for i in l:
temp = set()
for j in s:
curr = i ^ j
ans = max(curr, ans)
temp.add(curr)
s = s | temp
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | def calc(arr, k):
dp = [0] * 1024
dp[0] = 1
for ele in arr:
for j in range(1023, -1, -1):
neval = j ^ ele
if dp[j]:
dp[neval] = 1
ans = k
for i in range(1024):
if dp[i]:
ans = max(ans, i ^ k)
return ans
t = int(input())
while ... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for tc in range(int(input())):
n, k = map(int, input().split())
l = list(map(int, input().split()))
a = set()
a.add(k)
for i in l:
temp = a.copy()
for j in temp:
a.add(i ^ j)
print(max(a)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
for i in range(t):
n, k = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
temp = [[(0) for i in range(1024)] for i in range(n + 1)]
temp[0][0] = 1
for i in range(1, n + 1):
for j in range(1024):
temp[i][j] = temp[i - 1][j] or temp[i - 1]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMB... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | T = int(input())
for i in range(T):
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = []
dp = [0] * 1024
dp[0] = 1
dp1 = []
dp1 = [dp] * (n + 1)
for i in range(1, n + 1):
for j in range(1024):
if dp1[i - 1][j] == 1 or dp1[i - 1][j ^ a[i - 1]] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().split())
A = list(map(int, input().split()))
dp = [([0] * 1024) for _ in range(n + 1)]
dp[0][0] = 1
for i in range(len(A)):
dp[i][0] = 1
for elem in A:
dp[1][elem] = 1
for i in range(1, n + 1):
for j in range(1024)... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR A... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().split())
dp = [(0) for i in range(1024)]
dp[0] = 1
l = list(map(int, input().split()))
for i in l:
for j in range(1024):
if dp[j]:
val = i ^ j
dp[val] = 1
ans = k
for i in range(1024):
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for i in range(int(input())):
n, k = [int(x) for x in input().split()]
l = list(map(int, input().split()))
s = {k}
for i in l:
a = []
for j in s:
a.append(j ^ i)
for d in a:
s.add(d)
print(max(s)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | T = int(input())
for t in range(T):
n, k = map(int, input().split())
arr = [0] + [int(_) for _ in input().split()]
ans = 0
check = [(0) for _ in range(1024)]
check[0] = 1
for i in range(1, n + 1):
for j in range(1024):
index = j ^ arr[i]
if check[j]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
while t > 0:
t -= 1
n, k = map(int, input().split())
arr = list(map(int, input().split()))
dp = [0] * 1024
dp[0] = True
for i in range(len(arr)):
for j in range(0, 1024):
dp[arr[i] ^ j] |= dp[j]
ans = k
for i in range(0, 1024):
if dp[i]:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBE... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | def mp():
return map(int, input().split(" "))
def lst():
return list(mp())
for _ in range(int(input())):
n, k = mp()
a = lst()
pre = [(0) for i in range(n)]
pre[0] = a[0]
h = [(0) for i in range(2026)]
h[0] = 1
for i in range(n):
h[a[i]] = 1
for j in range(1024):
... | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NU... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | def answer():
dp = [[(False) for i in range(1025)] for i in range(n + 1)]
dp[0][0] = True
for i in range(1, n + 1):
for j in range(1025):
dp[i][j] = dp[i][j] | dp[i - 1][j]
if dp[i][j]:
dp[i][j ^ a[i - 1]] = True
ans = 0
for i in range(1025):
i... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMB... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | raw_input = input
for _ in range(int(raw_input())):
n, k = map(int, raw_input().split())
A = [int(x) for x in raw_input().split()]
dp = [False] * 1024
dp[k] = True
for i in A:
dp[i ^ k] = True
for j in range(1024):
if dp[j]:
dp[j ^ i] = True
for i in r... | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR V... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | import sys
sys.setrecursionlimit(10**6)
def max_xor(i, K, N, A, D):
if i == N:
return K
elif (i, K) in D:
return D[i, K]
else:
D[i, K] = max(max_xor(i + 1, K, N, A, D), max_xor(i + 1, K ^ A[i], N, A, D))
return D[i, K]
T = int(input())
ans = []
for _ in range(T):
N, ... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | def read():
return input().strip()
def readint():
return int(read())
t = readint()
for i in range(t):
n, k = map(int, read().split())
arr = [0] * 1025
a = [int(x) for x in read().split()]
for x in a:
arr[x] = 1
maxvalue = k
for x in a:
for j in range(1024):
... | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | import sys
sys.setrecursionlimit(10**7)
class Codechef:
dp = []
def __init__(self):
self.dp = [-1] * 1024
self.dp = [self.dp] * 1024
def maxXor(self, arr, n, k):
if n == 0:
return k
if self.dp[n][k] != -1:
return self.dp[n][k]
self.dp[n][k... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF ASSIGN VAR LIST FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP V... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | def solve():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
vis = set()
vis.add(k)
for i in arr:
temp = set()
for j in vis:
temp.add(i ^ j)
vis = vis.union(temp)
print(max(vis))
for t in range(int(input())):
solve() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CAL... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
while t:
n_k = [int(i) for i in input().split()]
n = n_k[0]
k = n_k[1]
arr = [int(i) for i in input().split()]
msb = max(arr)
index = 0
for i in range(31, -1, -1):
maxInd = index
maxEle = -2147483648
for j in range(index, n):
if arr[j] & 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN V... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | import sys
sys.setrecursionlimit(10**9)
def rec(a, i, curr, k, dp):
global mxor
if i >= len(a) - 1:
mxor = max(mxor, k ^ curr)
return mxor
if (curr, i) in dp:
return dp[curr, i]
for j in range(i + 1, len(a)):
curr ^= a[j]
r1 = rec(a, j, curr, k, dp)
cur... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VA... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | t = int(input())
for i in range(t):
n, p = map(int, input().split())
a = list(map(int, input().split()))
m = [([0] * 1024) for x in range(n + 1)]
m[0][0] = 1
max1 = 0
for j in range(1, n + 1):
for k in range(0, 1024):
m[j][k] = m[j - 1][k] + m[j - 1][k ^ a[j - 1]]
for j, ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR ... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | T = int(input())
for _ in range(T):
[n, k] = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
dp = [[0] * 1024] * (n + 1)
for i in range(n + 1):
for j in range(1024):
dp[i][j] = 0
dp[0][0] = 1
for i in range(1, n + 1):
for j in range(1024):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUM... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | import sys
sys.setrecursionlimit(10**6)
def rec(i, xor):
if i >= n:
return xor
if (i, xor) in dp:
return dp[i, xor]
dp[i, xor] = max(rec(i + 1, xor ^ a[i]), rec(i + 1, xor))
return dp[i, xor]
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, in... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | for _ in range(int(input())):
n, k = map(int, input().split())
a = [*map(int, input().split())]
s = set([0])
for i in a:
e = set(s)
for x in s:
e.add(x ^ i)
s = e
mx = k
for i in s:
mx = max(mx, i ^ k)
print(mx) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR F... |
Read problems statements in Mandarin Chinese and Russian.
You have an array of integers A_{1}, A_{2}, ..., A_{N}. The function F(P), where P is a subset of A, is defined as the XOR (represented by the symbol ⊕) of all the integers present in the subset. If P is empty, then F(P)=0.
Given an integer K, what is the ma... | import sys
sys.setrecursionlimit(10**9)
def solve(arr, index, N, K, ans, sub):
if index < 0:
return ans ^ K
if ans in sub[index]:
return sub[index][ans]
sub[index][ans] = max(
solve(arr, index - 1, N, K, ans, sub),
solve(arr, index - 1, N, K, ans ^ arr[index], sub),
)
... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR VAR IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR F... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
hat_per_map = defaultdict(list)
for idx, i in enumerate(hats):
for j in i:
hat_per_map[j - 1].append(idx)
@lru_cache(None)
def dp(hat, mask):
if mask == (1 << len(hats)) - 1:... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
n = len(hats)
dic = collections.defaultdict(list)
for i, hat in enumerate(hats):
for h in hat:
dic[h].append(i)
bfs = {(0): 1}
target = (1 << n) - 1
res = 0
for h ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VA... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
N = len(hats)
for i, h in enumerate(hats):
hats[i] = set(h)
mod = 10**9 + 7
@lru_cache(None)
def rec(cur, mask):
if cur > 41:
return 0
if mask == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
h2p = collections.defaultdict(list)
n = len(hats)
MOD = 10**9 + 7
for people, hat_list in enumerate(hats):
for h in hat_list:
h2p[h].append(people)
def dp(hat, mask):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
MOD = int(1000000000.0) + 7
n = len(hats)
d = {(0): 1}
rev = [[] for _ in range(41)]
for i, h in enumerate(hats):
for e in h:
rev[e].append(i)
for i in range(40):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR F... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
res, n, dp, hat2persons = 0, len(hats), {}, collections.defaultdict(list)
for person, arr in enumerate(hats):
for hat in arr:
hat2persons[hat - 1].append(person)
dp[0] = 1
for hat in rang... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR DICT FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF BIN_OP ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
n = len(hats)
fullMask = (1 << n) - 1
mp = defaultdict(list)
for idx, i in enumerate(hats):
for hat in i:
mp[hat - 1].append(idx)
mod = 10**9 + 7
@lru_cache(None)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMB... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
ownhat = {}
n = len(hats)
for i in range(n):
hat = hats[i]
for h in hat:
if h in ownhat:
ownhat[h].append(i)
else:
ownhat[h] = ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR BIN_OP FUNC_CALL VAR NU... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
hat2ppl = defaultdict(set)
for p, hats_i in enumerate(hats):
for h in hats_i:
hat2ppl[h].add(p)
if len(hats) > len(hat2ppl):
return 0
M = 10**9 + 7
@lru_cache(None)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
h2p = defaultdict(list)
n = len(hats)
mod = 10**9 + 7
for p, hat_list in enumerate(hats):
for h in hat_list:
h2p[h].append(p)
m = 1 << n
dp = [([0] * m) for _ in range(41)... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUM... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
hat2ppl = defaultdict(set)
for p, hats_i in enumerate(hats):
for h in hats_i:
hat2ppl[h].add(p)
M = 10**9 + 7
n = 1 << len(hats)
dp = [0] * n
dp[0] = 1
for i in ra... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
total = 1 << len(hats)
satisfy, bound = [0] * 41, 0
for i, likes in enumerate(hats):
for hat in likes:
satisfy[hat] |= 1 << i
bound = max(bound, hat)
MOD = 10**9 + 7
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP LIST NUMBER BI... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
htop = [[] for i in range(41)]
for p, prefer_hats in enumerate(hats):
for h in prefer_hats:
htop[h].append(p)
htop = list([h for h in htop if h])
num_hats, num_people = len(htop), len(hat... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF FUNC... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats) -> int:
MOD = 10**9 + 7
n = len(hats)
t = 1 << n
people = [[] for _ in range(41)]
for i, hat in enumerate(hats):
for h in hat:
people[h].append(i)
dp = [[(0) for _ in range(t)] for _ in range(41)]... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMB... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
max_hat = max([item for hat in hats for item in hat])
n = len(hats)
dp = [[(0) for _ in range(2**n)] for _ in range(max_hat + 1)]
for i in range(max_hat + 1):
dp[i][0] = 1
hat_bitmaps = []
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUM... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def _to_hat_to_people(self, person_to_hats):
min_hat, max_hat = None, None
for hats in person_to_hats:
for hat in hats:
if min_hat is None or hat < min_hat:
min_hat = hat
if max_hat is None or hat > max_hat:
... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR NONE NONE FOR VAR VAR FOR VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
h2p = defaultdict(list)
for i, hat in enumerate(hats):
for h in hat:
h2p[h].append(i)
n = len(hats)
dp, ndp = defaultdict(int), defaultdict(int)
for hat in range(0, 41):
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
dp = {}
n_ppl = len(hats)
hat_2_ppl = {}
for i in range(n_ppl):
for hat in hats[i]:
hat_2_ppl[hat] = hat_2_ppl.get(hat, []) + [i]
def dfs(hat, mask):
if mask == (1 <<... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST LIST VAR FUNC_DEF IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN VAR VAR VAR ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
mod = 10**9 + 7
k = len(hats)
persons = defaultdict(list)
for i, hs in enumerate(hats):
for h in hs:
persons[h].append(i)
dic = defaultdict(int)
dic[0] = 1
for hat... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
MOD = int(1000000000.0) + 7
n = len(hats)
dp = [[(0) for _ in range(1 << n)] for _ in range(41)]
rev = [[] for _ in range(41)]
for i, h in enumerate(hats):
for e in h:
rev[e].appe... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER NUMBER ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
self.visited = 0
hm = {}
for n, i in enumerate(hats):
for j in i:
if j not in hm:
hm[j] = [n]
else:
hm[j].append(n)
keys = list(hm.... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR LIST VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
numPeople = len(hats)
hatDesired = defaultdict(set)
MAX_HATS = 0
BIG_NUMBER = 10**9 + 7
for index, hatPreferences in enumerate(hats):
for hat in hatPreferences:
hatDesired[hat].ad... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR V... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
def helper(hat, assignedPeople):
if assignedPeople == target_state:
return 1
if hat > 40:
return 0
if dp[hat][assignedPeople] is not None:
return dp[hat][... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NONE RETURN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
tot = len(hats)
h = [([False] * tot) for i in range(41)]
for i in range(len(hats)):
for j in range(len(hats[i])):
h[hats[i][j]][i] = True
f = [([0] * (1 << tot)) for i in range(41)]
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
N = len(hats)
@lru_cache(None)
def helper(mask, i):
if i == 41:
if mask == 0:
return 1
else:
return 0
elif mask == 0:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FUNC_CALL ... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
const = 10**9 + 7
matr = [(0) for i in range(40)]
maxx = -1
used_h = set()
for j in range(len(hats)):
for i in hats[j]:
matr[i - 1] += 2**j
maxx = max(i - 1, maxx)... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats: List[List[int]]) -> int:
self.hat_to_man = collections.defaultdict(set)
for i, lt in enumerate(hats):
for hat in lt:
self.hat_to_man[hat].add(i)
self.hat_nums = sorted(self.hat_to_man)
self.hat_cnt = len(self.hat... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER... |
There are n people and 40 types of hats labeled from 1 to 40.
Given a list of list of integers hats, where hats[i] is a list of all hats preferred by the i-th person.
Return the number of ways that the n people wear different hats to each other.
Since the answer may be too large, return it modulo 10^9 + 7.
Example 1:... | class Solution:
def numberWays(self, hats):
ppl = len(hats)
hats_to_ppl = [[] for i in range(41)]
dp = [[(-1) for j in range(2**ppl)] for i in range(41)]
for i in range(ppl):
for j in hats[i]:
hats_to_ppl[j].append(i)
return self.dfs(1, hats_to_pp... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_DEF... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
dic = {v: i for i, v in enumerate(req_skills)}
dp = dict()
for i, people_skill in enumerate(people):
skill = 0
for single_skill in people_skil... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR LIST VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR FUN... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
num_skills, team_queue = len(req_skills), collections.deque()
bit_map, people_map = {
req_skills[i]: i for i in range(num_skills)
}, collections.defaultdi... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL V... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skill2num = {}
for i, skill in enumerate(req_skills):
skill2num[skill] = i
p2s = [0] * len(people)
for i, p in enumerate(people):
skil... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST ... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
INT_MAX = 2147483647
n = len(req_skills)
pskills = list()
target = (1 << n) - 1
dp = [INT_MAX for i in range(target + 1)]
parent = [list() for... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASS... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
lrs = len(req_skills)
skills = collections.defaultdict(list)
peo_skills = []
for i, skill in enumerate(people):
for s in skill:
sk... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR VAR IF VAR VAR RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR BIN... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skillid = {skill: i for i, skill in enumerate(req_skills)}
skillsets = {(0): []}
for i, p in enumerate(people):
skillmask = 0
for skill in p:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR B... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
def fulfill_skills(skills, person):
remaining_skills = deque()
for skill in skills:
if skill not in people[person]:
remai... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FU... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skillsMap = {s: i for i, s in enumerate(req_skills)}
peopleSkills = collections.defaultdict(set)
for i, p in enumerate(people):
for s in p:
... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR RETURN VAR B... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
skill_id_map = {skill: (1 << i) for i, skill in enumerate(req_skills)}
ids_indices_map = {(0): []}
for index, person_skills in enumerate(people):
person_i... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR LIST VAR IF FUNC_CALL V... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
mapping = {v: i for i, v in enumerate(req_skills)}
record = {(0): []}
for i, p in enumerate(people):
skills = 0
for s in p:
if... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR B... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
l = len(req_skills)
index_dict = {item: i for i, item in enumerate(req_skills)}
mydict = {(0): []}
for i, person in enumerate(people):
skill_list ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT NUMBER LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER ASSIGN VA... |
In a project, you have a list of required skills req_skills, and a list of people. The i-th person people[i] contains a list of skills that person has.
Consider a sufficient team: a set of people such that for every required skill in req_skills, there is at least one person in the team who has that skill. We can repr... | class Solution:
def smallestSufficientTeam(
self, req_skills: List[str], people: List[List[str]]
) -> List[int]:
n, m = len(req_skills), len(people)
key = {v: i for i, v in enumerate(req_skills)}
@functools.lru_cache(None)
def helper(cur=0):
if cur == (1 << ... | CLASS_DEF FUNC_DEF VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN LIST ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR BIN_OP NUMBE... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.