description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
list_size = 2100
f_list = [1] * list_size
f_r_list = [1] * list_size
for i in range(list_size - 1):
f_list[i + 1] = int(f_list[i] * (i + 2) % MOD)
def power(n, x):
if x == 1:
return n
elif x % 2 == 0:
return power(int(n * n % MOD), int(x / 2))
else:
return int(n... | ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_C... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
comb = 1
power = 1
fact = 1
M = 998244353
for i in range(k):
comb = comb * (n - 1 - i)
power *= m - 1
power = power % M
fact *= k - i
print(comb // fact % M * m * (power % M) % M) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
def pow(base, exp):
if exp == 0:
return 1
if exp % 2 == 1:
return pow(base, exp - 1) * base % MOD
tmp = pow(base, exp // 2)
return tmp * tmp % MOD
def inv_mod(x):
return pow(x, MOD - 2)
def C(n, k):
if k < n // 2:
return C(n, n - k)
result = 1
... | ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
def f(x):
ans = 1
for i in range(1, x):
ans = ans * i
return ans
n, m, k = map(int, input().split())
print(m * (m - 1) ** k * f(n) // f(k + 1) // f(n - k) % MOD) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | s = input()
s = s.split(" ")
n = int(s[0])
m = int(s[1])
k = int(s[2])
ans = 1
if k > 0:
for i in range(n - k, n):
ans = ans * i
for i in range(1, k + 1):
ans = ans // i
ans = ans * m
for i in range(k):
ans = ans * (m - 1)
pass
print(ans % 998244353) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
inf = float("inf")
mod = 998244353
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline()
def main():
n, m, k = get_ints()
dp[1][0] = m
for i in range(1, n):
... | IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def calc(n, k):
return fact[n] * pow(fact[n - k] * fact[k], mod - 2, mod) % mod
mod = 998244353
n, m, k = map(int, input().split())
fact = [1]
for i in range(1, 2001):
fact.append(fact[-1] * i % mod)
print(calc(n - 1, k) * m * pow(m - 1, k, mod) % mod) | FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | stdin = lambda type_="int", sep=" ": list(map(eval(type_), input().split(sep)))
joint = lambda sep=" ", *args: sep.join(
str(i) if type(i) != list else sep.join(map(str, i)) for i in args
)
def binomial(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
... | ASSIGN VAR STRING STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_C... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def power(x, y):
res = 1
while y != 0:
if y & 1:
res = res * x % mod
x = x * x % mod
y >>= 1
return res
n, m, k = map(int, input().split())
mod = 998244353
jc = [1]
for i in range(n - 1):
jc.append(jc[i] * (i + 1) % mod)
ans = jc[n - 1] * power(m - 1, k) % mod * m %... | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
mod = 998244353
dp = [[(0) for i in range(n)] for j in range(n)]
dp[0][0] = m
for i in range(1, n):
for j in range(0, min(i + 1, k + 1)):
if j == 0:
dp[i][j] = dp[i - 1][j]
elif j == i + 1:
dp[i][j] = dp[i - 1][j] * (m - 1) % mod
el... | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR B... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | l = list(map(int, input().strip().split()))
n = l[0]
m = l[1]
k = l[2]
mod = 998244353
soma = 0
def power_mod(base, power, mod):
res = 1
while power:
if power % 2 == 1:
res = res * base % mod
base = base * base % mod
power = power >> 1
return res
def inverse(n, mod):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR AS... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = list(map(int, input().split()))
mod = 998244353
same_bricks = n - 1 - k
total = m
for i in range(k):
total *= m - 1
total %= mod
val = 1
for i in range(n - k, n):
val *= i
for i in range(1, k + 1):
val //= i
total *= val
total %= mod
print(total) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = [int(x) for x in input().split()]
def perm(n, k):
s = 1
for i in range(n - k + 1, n + 1):
s *= i
return s
def choose(n, k):
if k > n // 2:
return choose(n, n - k)
else:
return perm(n, k) // perm(k, k)
ans = m
for i in range(0, k):
ans = ans * (m - 1) % 998... | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN V... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
n, nColors, nDiff = map(int, input().split())
dp = [[(0) for _ in range(nDiff + 1)] for _ in range(n)]
dp[0][0] = nColors
for size in range(1, n):
for cnt in range(nDiff + 1):
dp[size][cnt] += dp[size - 1][cnt]
dp[size][cnt] %= MOD
if cnt - 1 >= 0:
dp[size][cnt] +... | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR IF BIN_OP... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
dp = [([0] * (n + 1)) for i in range(n)]
MOD = 998244353
dp[0][0] = m
for i in range(1, n):
for j in range(k + 1):
dp[i][j + 1] += dp[i - 1][j] * (m - 1)
dp[i][j] += dp[i - 1][j]
dp[i][j + 1] %= MOD
dp[i][j] %= MOD
print(dp[n - 1][k]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def ncr(n, r):
return fact(n) // (fact(r) * fact(n - r))
def fact(n):
res = 1
for i in range(2, n + 1):
res = res * i
return res
n, m, k = map(int, input().split())
mod = 998244353
a = ncr(n - 1, k)
if k >= 1:
c = (m - 1) ** k
else:
c = 1
c = c % mod
ans = a * m * c
print(ans % mod) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | N, M, K = map(int, input().split())
MOD = 998244353
dp = [([0] * 2002) for i in range(2002)]
dp[1][0] = M
for i in range(1, N):
for j in range(K + 1):
dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD
dp[i + 1][j + 1] = dp[i][j] * (M - 1) % MOD
print(dp[N][K]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
mod = 998244353
bricks, colors, left = map(int, input().split())
dp = [([0] * (left + 1)) for i in range(bricks + 1)]
if left == 0:
print(colors)
sys.exit()
for i in range(1, bricks + 1):
dp[i][0] = colors
for i in range(1, bricks + 1):
for j in range(1, left + 1):
dp[i][j] = (dp[i -... | IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | s = input().split()
n, m, k = list(map(int, s))
MOD = 998244353
ans = m
for i in range(k):
ans = ans * (m - 1) % MOD
if k > n // 2:
k = n - 1 - k
for i in range(1, k + 1):
ans = ans * (n - 1 - k + i) // i
print(ans % MOD) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN V... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def binomialCoef(n, k):
C = [[(0) for x in range(k + 1)] for x in range(n + 1)]
mod = 998244353
for i in range(n + 1):
for j in range(min(i, k) + 1):
if j == 0 or j == i:
C[i][j] = 1
else:
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod
ret... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BI... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = list(map(int, input().split()))
ans = 1
for i in range(1, k + 1):
ans *= n - i
for i in range(k, 0, -1):
ans //= i
ans = ans * m % 998244353
for i in range(k):
ans = ans * (m - 1) % 998244353
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
def bpow(a, b):
sol = 1
while b:
if b & 1:
sol *= a
if sol >= MOD:
sol %= MOD
a *= a
if a >= MOD:
a %= MOD
b >>= 1
return sol
fac = []
fac += [1]
for i in range(1, 2001):
fac.append(fac[i - 1] * i % M... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
def combinations(n, k):
return factorial(n) // (factorial(k) * factorial(n - k))
def main():
n, m, k = map(int, input().split())
print(combinations(n - 1, k) * m * (m - 1) ** k % 998244353)
main() | FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUM... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | def fact(n):
if n == 0:
return 1
else:
return fact(n - 1) * n
def C(n, k):
return fact(n) // (fact(n - k) * fact(k))
n, m, k = map(int, input().split())
print(m * (m - 1) ** k * C(n - 1, k) % 998244353) | FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FUNC... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | mod = 998244353
n, m, k = map(int, input().split())
a = pow(m - 1, k, mod) * m % mod
for i in range(n - k, n):
a = a * i
for i in range(1, k + 1):
a //= i
print(a % mod) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split(" "))
MOD = 998244353
dp = [([0] * (k + 1)) for _ in range(n)]
dp[0][0] = m
for i in range(1, n):
for j in range(min(i + 1, k + 1)):
dp[i][j] = (
(0 if j == 0 else dp[i - 1][j - 1] * (m - 1) % MOD) + dp[i - 1][j]
) % MOD
print(dp[-1][-1]) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = list(map(int, input().split()))
d = [([0] * (k + 1)) for _ in range(0, n + 1)]
MOD = 998244353
for i in range(1, n + 1):
for j in range(0, k + 1):
if j == 0:
d[i][j] = m
else:
d[i][j] = (d[i - 1][j] + d[i - 1][j - 1] * (m - 1)) % MOD
print(d[n][k]) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIG... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
n, m, k = map(int, input().split())
a = [1]
for _ in range(n - 1):
a = [(sum(x) % MOD) for x in zip([0] + a, a + [0])]
print(m * pow(m - 1, k, MOD) * a[k] % MOD) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP LIST NUMBER VAR BIN_OP VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBE... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | data = input().split()
n = int(data[0])
m = int(data[1])
k = int(data[2])
K = 998244353
gt = [(0) for i in range(2005)]
rev = [(0) for i in range(2005)]
def mu(a, n):
if n == 0:
return 1
q = mu(a, n // 2)
if n % 2 == 0:
return q * q % K
return q * q % K * a % K
gt[0] = rev[0] = 1
for... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP ... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = map(int, input().split())
mod = 998244353
def combination_mod(k, n, mod):
fact_k = 1
for i in range(2, k + 1):
fact_k = fact_k * i % mod
fact_n = 1
for i in range(2, n + 1):
fact_n = fact_n * i % mod
fact_n_k = 1
for i in range(2, n - k + 1):
fact_n_k = fact_n... | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FU... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
MOD = 998244353
n, m, k = list(map(int, input().strip().split()))
memo = dict()
def C(n, m, k, first):
if n == 0:
if k == 0:
return 1
else:
return 0
if k == 0:
if first:
return m
else:
return 0
if (n, m, k, first) ... | IMPORT ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR NUMBER IF VAR RETURN VAR RETURN NUMBER IF VAR VAR VAR VAR VAR RETURN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | R = lambda: map(int, input().split())
n, m, k = R()
dp = [([0] * (k + 2)) for _ in range(n + 2)]
for i in range(1, n + 1):
dp[i][0] = m
for i in range(1, n + 1):
for j in range(1, k + 1):
dp[i][j] = (dp[i - 1][j] + (m - 1) * dp[i - 1][j - 1]) % 998244353
print(dp[n][k]) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER B... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | M = 998244353
def f(k):
r = 1
for i in range(2, k + 1):
r *= i
return r
n, m, k = map(int, input().split())
print(f(n - 1) * pow(f(k) * f(n - k - 1), M - 2, M) * m * pow(m - 1, k, M) % M) | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | MOD = 998244353
def power(x, a):
if a == 0:
return 1
z = power(x, a // 2)
z = z * z % MOD
if a % 2:
z = z * x % MOD
return z
def fact(n):
factn = 1
for i in range(2, n + 1):
factn = factn * i % MOD
return factn
def ncr(n, r):
return fact(n) * power(fact(... | ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR R... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | import sys
sys.setrecursionlimit(1000000)
M = 998244353
def Qpow(x, y):
if y == 0:
return 1
else:
ret = Qpow(x, int(y / 2)) % M
ret *= ret
ret %= M
if y % 2 == 1:
ret *= x
ret %= M
return ret
n, m, k = map(int, input().split())
fact = ... | IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_C... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | mod = 998244353
fac = [1]
for i in range(1, 2001):
fac.append(fac[-1] * i % mod)
def fexp(x, y):
ans = 1
while y > 0:
if y % 2 == 1:
ans = ans * x % mod
x = x * x % mod
y //= 2
return ans
def rev(x):
return fexp(x, mod - 2)
def c(n, k):
return fac[n] * r... | ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CA... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | P = 998244353
def C(n, k):
nonlocal P
k = min(k, n - k)
p = 1
for i in range(n, n - k, -1):
p *= i
for i in range(k, 0, -1):
assert p % i == 0
p //= i
return p % P
n, m, k = list(map(int, input().split()))
r = C(n - 1, k)
r = r * m % P
for i in range(k):
r = r * (... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN V... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = list(map(int, input().split()))
MOD = 998244353
ans = m * pow(m - 1, k, MOD) % MOD
for i in range(n - k, n):
ans = ans * i
for i in range(n - k, n):
ans = ans // (n - i)
print(ans % MOD) | ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC... |
On his free time, Chouti likes doing some housework. He has got one new task, paint some bricks in the yard.
There are $n$ bricks lined in a row on the ground. Chouti has got $m$ paint buckets of different colors at hand, so he painted each brick in one of those $m$ colors.
Having finished painting all bricks, Chouti... | n, m, k = [int(x) for x in input().split()]
dp = [0] * (n - 1)
if len(dp) > 0:
dp[0] = n - 1
n -= 1
for i in range(1, n):
n -= 1
dp[i] = dp[i - 1] * n // (i + 1)
if k == 0:
print(m)
else:
print(dp[k - 1] * m * (m - 1) ** k % 998244353)
else:
print(m) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR NUMBER E... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | import sys
n, k = list(map(int, sys.stdin.readline().split()))
profits = [int(sys.stdin.readline()) for i in range(n)]
total = sum(profits)
if k == n:
print(total)
else:
x = profits[: k + 1]
min_value = min(x)
min_index = x.index(min_value)
for i in range(k + 1, n):
if i - min_index >= k:
... | IMPORT 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 VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_O... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | arr1 = [int(i) for i in input().strip().split(" ")]
n, k = arr1[0], arr1[1]
arr2 = []
for i in range(n):
arr2.append(int(input().strip()))
max_profit = sum(arr2)
def minimum_pairings(array1):
array2 = []
i = 0
while i < len(array1) - 1:
array2.append(min(array1[i], array1[i + 1]))
i +=... | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUM... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | n, k = map(int, input().split())
a = []
for i in range(n):
a.append(int(input()))
a.append(0)
dp = [(-1) for i in range(n + 2)]
val = [(0) for i in range(k + 1)]
val[k] = sum(a[k:])
for i in reversed(range(k)):
val[i] = a[i] + val[i + 1]
for i in reversed(range(n - k, n + 2)):
dp[i] = 0
for i in reversed(ra... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | inp = input("")
con = inp.split(" ")
n = int(con[0])
k = int(con[1])
cost = []
for i in range(n):
a = input("")
cost.append(int(a))
sliced = cost[:k]
scam = sum(sliced)
R = [(scam - i) for i in sliced[::-1]] + [scam]
inter = scam
a = k + 1
b = n + 1
cumm = a
while cumm < b:
for j in range(a, b):
x =... | ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP ... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | import sys
class Max_slice:
def __init__(self, w):
self.w = w
self.x = []
def add(self, i, val):
while self.x and val >= self.x[-1][1]:
self.x.pop()
while self.x and self.x[0][0] <= i - self.w:
self.x.pop(0)
self.x.append((i, val))
retu... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF WHILE VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR L... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | def f(b, index):
return
str = input().split()
n, k = int(str[0]), int(str[1])
b = []
dp = [([0] * 2) for i in range(n)]
for i in range(n):
b.append(int(input()))
dp[0][0] = 0
dp[0][1] = b[0]
max_index = 0
for i in range(1, n):
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1])
if i < k:
dp[i][1] = dp[... | FUNC_DEF RETURN ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | N, K = map(int, input().split())
X = [0]
for _ in range(N):
X.append(int(input()))
nocut = [(0) for i in range(N + 1)]
cut = [(0) for i in range(N + 1)]
lastcut = 0
roll = 0
for i in range(1, N + 1):
cut[i] = max(cut[i - 1], nocut[i - 1])
if lastcut < i - K:
roll = -1
for j in range(0, K):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR N... |
ADZEN is a popular advertising firm in your city that owns all $n$ billboard locations on Main street. The city council passed a new zoning ordinance mandating that no more than $\boldsymbol{\mbox{k}}$ consecutive billboards may be up at any given time. For example, if there are $n=3$ billboards on Main street and $k=1... | NK = input().split(" ")
N = int(NK[0])
K = int(NK[1])
profits = []
for billboard in range(N):
profits.append(int(input()))
total = sum(profits)
if K >= N:
print(total)
elif K == 0:
print(0)
else:
DPtable = []
queue = []
for index, profit in enumerate(profits[: K + 1]):
DPtable.append(pro... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIS... |
Moving ahead, Gudi now enters a room where the floor is divided into N x M square tiles, forming a grid with N rows and M columns.
Each square in the grid contains a number of Magical Orbs that Gudi has to absorb if she steps on it. Each Orb increases her Kii power, which is needed to fight the demons. Gudi enters the... | T = int(input())
for t in range(0, T):
N, M, K = [int(x) for x in input().split()]
a = []
for i in range(0, N):
a.append([int(x) for x in input().split()])
d = []
for i in range(0, N):
d.append([])
for j in range(0, M):
d[i].append(set())
if a[0][0] <= K:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR L... |
Moving ahead, Gudi now enters a room where the floor is divided into N x M square tiles, forming a grid with N rows and M columns.
Each square in the grid contains a number of Magical Orbs that Gudi has to absorb if she steps on it. Each Orb increases her Kii power, which is needed to fight the demons. Gudi enters the... | def process(N, M, MAX):
table[0][0] = [arr[0][0]]
for i in range(1, M):
table[0][i] = [table[0][i - 1][0] + arr[0][i]]
for i in range(1, N):
table[i][0] = [table[i - 1][0][0] + arr[i][0]]
for i in range(1, N):
for j in range(1, M):
ans = set()
val = arr[i]... | FUNC_DEF ASSIGN VAR NUMBER NUMBER LIST VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER LIST BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBE... |
This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of $m$ and the time limit. You need to solve both subtasks in order to hack this one.
There are $n+1$ distinct colours in the universe, numbered $0$ through $n$. There is a strip of paper $... | n, m = map(int, input().split())
l = list(map(int, input().split()))
index = [[(0) for i in range(n)] for j in range(n)]
for i in range(n):
mini = 10000000000000
for j in range(i, n):
if l[j] < mini:
inde = j
mini = l[j]
index[i][j] = inde
prime = 998244353
d = {}
val = [... | 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 VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR ... |
This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of $m$ and the time limit. You need to solve both subtasks in order to hack this one.
There are $n+1$ distinct colours in the universe, numbered $0$ through $n$. There is a strip of paper $... | def main():
line = input().split()
n = int(line[0])
line = input().split()
v = [int(x) for x in line]
mod = 998244353
dp = [([1] * (n + 5)) for i in range(n + 5)]
for sz in range(2, n + 1):
for lo in range(1, n - sz + 2):
hi = lo + sz - 1
pos, num = -1, n + 5
... | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL V... |
This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of $m$ and the time limit. You need to solve both subtasks in order to hack this one.
There are $n+1$ distinct colours in the universe, numbered $0$ through $n$. There is a strip of paper $... | import sys
input = sys.stdin.readline
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [(a - 1) for a in A]
MININDLIST = [([i] * m) for i in range(m)]
for i in range(m):
MIN = A[i]
MININDNOW = i
for j in range(i, m):
if A[j] < MIN:
MIN = A[j]
MI... | IMPORT ASSIGN 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 BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FOR VAR FU... |
This is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of $m$ and the time limit. You need to solve both subtasks in order to hack this one.
There are $n+1$ distinct colours in the universe, numbered $0$ through $n$. There is a strip of paper $... | class SparseTable:
def __init__(self, array, n):
n = len(array)
self.row_size = n.bit_length()
self.log_table = [0] * (n + 1)
for i in range(2, n + 1):
self.log_table[i] = self.log_table[i // 2] + 1
self.sparse_table = [([0] * n) for _ in range(self.row_size)]
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER V... |
Given string s consisting of digits 0-9 and a number N, the task is to count the number of subsequences that are divisible by N.
Note: Answer can be large, output answer modulo 10^{9} + 7
Example 1:
Input: s = "1234", N = 4
Output: 4
Explanation: The subsequences 4, 12, 24 and
124 are divisible by 4.
Example 2:
Input:... | class Solution:
def countDivisibleSubseq(self, str, n):
mod = int(1000000000.0 + 7)
l = len(str)
dp = [[(0) for x in range(l)] for y in range(n)]
dp[int(str[0]) % n][0] += 1
for i in range(1, l):
dp[int(str[i]) % n][i] += 1
for j in range(n):
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR... |
Given string s consisting of digits 0-9 and a number N, the task is to count the number of subsequences that are divisible by N.
Note: Answer can be large, output answer modulo 10^{9} + 7
Example 1:
Input: s = "1234", N = 4
Output: 4
Explanation: The subsequences 4, 12, 24 and
124 are divisible by 4.
Example 2:
Input:... | class Solution:
def countDivisibleSubseq(self, s, N):
memo = {}
s = str(s)
return (getcount(s, 0, 0, N, memo) - 1) % (10**9 + 7)
def getcount(s, idx, rem, k, memo):
n = len(s)
if idx == n:
return 1 if rem == 0 else 0
if hashed(idx, rem) in memo:
return memo[has... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR... |
Given string s consisting of digits 0-9 and a number N, the task is to count the number of subsequences that are divisible by N.
Note: Answer can be large, output answer modulo 10^{9} + 7
Example 1:
Input: s = "1234", N = 4
Output: 4
Explanation: The subsequences 4, 12, 24 and
124 are divisible by 4.
Example 2:
Input:... | class Solution:
def countDivisibleSubseq(self, s, N):
MOD = 10**9 + 7
def rec(index, rem):
if index == len(s):
return int(rem == 0)
nt = rec(index + 1, rem)
tk = rec(index + 1, (rem * 10 + int(s[index])) % N)
return nt + tk
d... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR NUMBER V... |
Given string s consisting of digits 0-9 and a number N, the task is to count the number of subsequences that are divisible by N.
Note: Answer can be large, output answer modulo 10^{9} + 7
Example 1:
Input: s = "1234", N = 4
Output: 4
Explanation: The subsequences 4, 12, 24 and
124 are divisible by 4.
Example 2:
Input:... | class Solution:
def countDivisibleSubseq(self, s, N):
mod = int(1000000007)
l = len(s)
dp = [[(0) for x in range(n)] for y in range(l)]
for i in range(0, l):
dp[i][int(s[i]) % N] = 1
dp[i][int(s[i]) % N] = dp[i][int(s[i]) % N] % mod
for i in range(1, ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VA... |
You are given a directed graph $G$ which can contain loops (edges from a vertex to itself). Multi-edges are absent in $G$ which means that for all ordered pairs $(u, v)$ exists at most one edge from $u$ to $v$. Vertices are numbered from $1$ to $n$.
A path from $u$ to $v$ is a sequence of edges such that:
vertex $u$ ... | import sys
sys.setrecursionlimit(600000)
def dfs_1(v):
q = [v, 0]
while len(q) != 0:
i = q.pop()
v = q.pop()
if i == 0:
color[v] = 1
if i == len(g[v]):
color[v] = 2
continue
q.append(v)
q.append(i + 1)
w = g[v][i]
... | IMPORT EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ... |
You are given a directed graph $G$ which can contain loops (edges from a vertex to itself). Multi-edges are absent in $G$ which means that for all ordered pairs $(u, v)$ exists at most one edge from $u$ to $v$. Vertices are numbered from $1$ to $n$.
A path from $u$ to $v$ is a sequence of edges such that:
vertex $u$ ... | import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def scc_dfs1(s, links, status, postorder):
stack = [s]
status[s] = 0
while stack:
v = stack[-1]
limit = len(links[v])
while status[v] < limit:
u = links[v][status[v]]
status[v] += 1
... | IMPORT ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
dp = [[(-1) for i in range(n)] for j in range(n)]
def recursive(string, left=0, right=n - 1):
if left > right:
return True
if left == right:
dp[left][right] = Tru... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, str):
n = len(str)
dp = [0] * n
palindrome = [([False] * n) for _ in range(n)]
for i in range(n):
min_cut = i
for j in range(i + 1):
if str[i] == str[j] and (i - j < 2 or palindrome[j + 1][i - 1])... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR N... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
mp = {}
res = self.solve(string, mp)
return res
def solve(self, string, mp):
if len(string) == 0 or string == string[::-1]:
return 0
if string in mp:
return mp[string]
res = float("i... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR V... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s):
def calc(i):
if i == len(s):
return 0
if dp[i] != -1:
return dp[i]
else:
mxc = float("inf")
for k in range(i, len(s)):
if s[i : k + 1] ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
dp = [0] * (n + 1)
dp[n] = 0
for i in reversed(range(n)):
minCost = float("inf")
for j in range(i, n):
cur_string = string[i : j + 1]
if self.isPalindrome(... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NU... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
dp = [(0) for _ in range(n + 1)]
for i in range(n - 1, -1, -1):
minCuts = float("inf")
for j in range(i, n):
if self.isPalindrome(string[i : j + 1]):
cuts = 1 ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR F... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
def ispalindrome(strs, st, end):
while st <= end:
if strs[st] == strs[end]:
st += 1
end -= 1
else:
return False
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, str):
n = len(str)
P = [[(False) for _ in range(n)] for _ in range(n)]
for i in range(n):
P[i][i] = True
for L in range(2, n + 1):
for i in range(n - L + 1):
j = i + L - 1
if L == ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | def check(s):
if s == s[::-1]:
return True
else:
return False
class Solution:
def palindromicPartition(self, string):
dp = {}
def fun(s, i, j):
if i >= j:
return 0
if check(s[i:j]):
return 0
if (i, j) in ... | FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, S):
def palind(f):
l = len(f)
for i in range(l // 2):
if f[i] != f[l - i - 1]:
return 0
return 1
def manu(i, n, s):
if i == n:
return 0
if... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s):
n = len(s)
dp = [0] * (n + 1)
p = [([False] * (n + 1)) for _ in range(n + 1)]
for i in range(1, n + 1):
cost = float("inf")
for k in range(i, 0, -1):
if s[k - 1] == s[i - 1] and (i - k <= 2 or... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUM... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def ispalindrome(self, start, end, string):
while start < end:
if string[start] != string[end]:
return False
start += 1
end -= 1
return True
def palindromicPartition(self, string):
n = len(string)
dp = [(0) for... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VA... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, S):
N = len(S)
isp = [([True] * N) for _ in range(N)]
for add in range(1, N):
for j in range(N - add):
isp[j][j + add] = S[j] == S[j + add] and isp[j + 1][j + add - 1]
dp = [1] * N + [0]
for i in rang... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER V... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
dp = [(0) for i in range(len(string))]
p = [[(False) for i in range(len(string))] for j in range(len(string))]
for i in range(len(string)):
m = i
for j in range(i + 1):
if string[i] == string[j] ... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
dp = [(-1) for i in range(n)]
return self.f(0, n, string, dp) - 1
def f(self, i, n, string, dp):
mincost = float("inf")
if i == n:
return 0
if dp[i] != -1:
return dp[... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NU... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def __init__(self):
self.res = -float("inf")
def check_palin(self, x):
n = len(x)
for i in range(n // 2):
if x[i] != x[-i - 1]:
return False
return True
def solve(self, i, j, st, dp):
if i >= j:
return 0
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VA... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def is_palindrome(string, i, j):
while i < j:
if string[i] != string[j]:
return False
i += 1
j -= 1
return True
def palindromicPartition(self, string):
n = len(string)
dp1 = [([False] * n) for _ in range(n)]
... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VA... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def isPalin(self, i, j, string):
while i < j:
if string[i] != string[j]:
return False
j -= 1
i += 1
return True
def recur(self, i, string, n, dp, dpP):
if i == n:
return 0
if dp[i] != -1:
... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
P = [([False] * n) for _ in range(n)]
for i in range(n):
P[i][i] = True
for i in range(n - 1):
P[i][i + 1] = string[i] == string[i + 1]
for l in range(3, n + 1):
for i... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_C... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s):
def check(i, j, s):
while i < j:
if s[i] != s[j]:
return False
i += 1
j -= 1
return True
dp = [-1] * len(s)
def f(i, s):
if i == len(... | CLASS_DEF FUNC_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF F... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
is_pali = [[(False) for i in range(len(string))] for j in range(len(string))]
for k in range(len(string)):
i, j = 0, k
while j < len(string):
if k == 0:
is_pali[i][j] = True
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
dp = [0] * n
pal = [([False] * n) for _ in range(n)]
for i in range(n):
pal[i][i] = True
for l in range(2, n + 1):
for i in range(n - l + 1):
j = i + l - 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | def chk(l, r, s):
while l < r:
if s[l] == s[r]:
r -= 1
l += 1
else:
return False
return True
def f(l, r, s, dp):
if (l, r) in dp:
return dp[l, r]
if chk(l, r, s):
return 1
ans = r - l + 1
for i in range(l, r):
if chk(l... | FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
def ispal(s):
return s == s[::-1]
def solve(i, j, string):
if i >= j:
return 0
if dp[i][j] != -1:
return dp[i][j]
if ispal(string[i : j + 1]):
re... | CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP V... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | def is_palindrome(s):
return s == s[::-1]
class Solution:
def helper(self, s):
if self.d.get(s) is not None:
return self.d[s]
if not s:
return 0
ans = 10**9
for i in range(len(s)):
if is_palindrome(s[: i + 1]):
ans = min(ans,... | FUNC_DEF RETURN VAR VAR NUMBER CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR NONE RETURN VAR VAR IF VAR RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | import sys
class Solution:
def isPalindrome(self, str, i, j):
while i < j:
if str[i] != str[j]:
return False
i += 1
j -= 1
return True
def palindromicPartition(self, str):
n = len(str)
dp = [0] * (n + 1)
for i in ran... | IMPORT CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR V... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
def ispallindrome(s, i, j, dp):
if i >= j:
dp[i][j] = 0
return dp[i][j]
if s[i] == s[j]:
dp[i][j] = ispallindrome(s, i + 1, j - 1, dp)
return dp[i][j]
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR VAR VAR RETURN VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VA... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
if n != 0:
dp = [([False] * n) for i in range(n)]
for i in range(n):
dp[i][i] = True
if i != n - 1:
if string[i] == string[i + 1]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER A... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s):
n = len(s)
dp = [[(-1) for i in range(n + 2)] for j in range(n + 2)]
def ispal(st):
return st == st[::-1]
def solve(i, j):
if i >= j or ispal(s[i : j + 1]):
return 0
if dp[i][j] ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR VAR NUMBER FUNC_DEF IF VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | def helper(string, i, n, dp, ans):
ans[0] = 0
for j in range(1, n):
if dp[0][j]:
ans[j] = 0
else:
temp = int(1000000000.0)
for i in range(j, 0, -1):
if dp[i][j]:
temp = min(temp, ans[i - 1])
ans[j] = temp + 1
c... | FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VA... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | import sys
class Solution:
def palindromicPartition(self, str1):
n = len(str1)
C = [0] * (n + 1)
P = [[(False) for x in range(n + 1)] for y in range(n + 1)]
for i in range(n):
P[i][i] = True
for L in range(2, n + 1):
for i in range(n - L + 1):
... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s: str) -> int:
n = len(s)
dp = [([False] * n) for _ in range(n)]
cuts = [0] * n
for i in range(n):
dp[i][i] = True
for j in range(i):
if s[i] == s[j] and (i == j + 1 or dp[j + 1][i - 1]):
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
dp = {}
return self.helper(string, dp)
def helper(self, string, dp):
n = len(string)
if n == 0:
dp[string] = 0
return 0
if string in dp:
return dp[string]
if string == st... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VA... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s):
N = len(string)
dp = [[(-1) for i in range(N + 2)] for j in range(N + 2)]
def ispalindrome(s1):
return s1 == s1[::-1]
def solve(i, j):
if i >= j:
return 0
if dp[i][j] != -1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER F... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string: str) -> int:
n = len(string)
dp = [([False] * n) for _ in range(n)]
for i in range(n):
dp[i][i] = True
for length in range(2, n + 1):
for i in range(n - length + 1):
j = i + length - 1
... | CLASS_DEF FUNC_DEF VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, s):
def checkPalindrome(string, i, j):
l, r = i, j
while l < r:
if string[l] != string[r]:
return False
l += 1
r -= 1
return True
def solve(string... | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FU... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
def ispalindrome(start, end, str):
while start < end:
if str[start] != str[end]:
return False
start += 1
end -= 1
return True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR V... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def palindromicPartition(self, string):
n = len(string)
def check_pali(s, e):
i, j = s, e
while i < j:
if string[i] != string[j]:
return False
i += 1
j -= 1
return True
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER IF VAR VAR NUMBER RET... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def fun(self, i, s, n, dp):
if i == n:
return 0
if dp[i] != -1:
return dp[i]
temp = ""
mini = float("inf")
for j in range(i, n):
temp += s[j]
if temp == temp[::-1]:
cost = 1 + self.fun(j + 1, s, ... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR V... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | import sys
sys.setrecursionlimit(10**7)
class Solution:
def palindromicPartition(self, string):
d = dict()
def dfs(s, i, j):
if i == j:
s1 = s[i : j + 1]
if s1 == s1[::-1]:
return -1
return 10**9
if d.ge... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NONE RETURN VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR A... |
Given a string str, a partitioning of the string is a palindrome partitioning if every sub-string of the partition is a palindrome. Determine the fewest cuts needed for palindrome partitioning of the given string.
Example 1:
Input: str = "ababbbabbababa"
Output: 3
Explaination: After 3 partitioning substrings
are "a",... | class Solution:
def isPalindrome(self, string, a, b):
while a <= b:
if string[a] != string[b]:
return False
a += 1
b -= 1
return True
def palindromicPartition(self, string):
n = len(string)
dp = [(-1) for _ in range(n + 1)]
... | CLASS_DEF FUNC_DEF WHILE VAR VAR IF VAR VAR VAR VAR RETURN NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.