This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(input()) | |
respect = [1] * (n + 1) | |
for i in range(1, n + 1): | |
p, c = map(int, input().split()) | |
if not c: | |
respect[i] = respect[p] = 0 | |
res = set(i for i in range(1, n + 1) if respect[i]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def forbidden_integer(): | |
n, k, x = map(int, input().split()) | |
if x != 1: | |
# We can always form n using 1's | |
print("YES") | |
print(n) | |
print(" ".join(["1"] * n)) | |
elif n > 1 and k > 1: | |
# We can for n using 2's and possibly one 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# input | |
n, s = map(int, input().split()) | |
a = [0] + list(map(int, input().split())) + [0] | |
b = [0] + list(map(int, input().split())) + [0] | |
# logic | |
reachable = False | |
for i in range(1, n + 1): | |
if i == 1 and a[i] == 0: | |
print("NO") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def long_jumps(): | |
# input | |
n = int(input()) | |
a = list(map(int, input().split())) | |
# logic | |
globalMaxScore = float("-inf") | |
ptr = 0 | |
while ptr < n: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write your MySQL query statement below | |
select p.product_id, ifnull(round(sum(p.price * u.units) / sum(u.units), 2), 0) as average_price | |
from Prices p left join UnitsSold u on p.product_id=u.product_id and u.purchase_date between p.start_date and p.end_date | |
group by p.product_id; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sequence_game(): | |
n = int(input()) | |
b = list(map(int, input().split())) | |
res = [b[0]] | |
for i in range(1, n): | |
if b[i] < b[i - 1]: | |
res.append(1) | |
res.append(b[i]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def target_practice(): | |
# hardcode the target matrix since it is always 10 * 10 matrix with fixed values | |
target = [ | |
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], | |
[1, 2, 2, 2, 2, 2, 2, 2, 2, 1], | |
[1, 2, 3, 3, 3, 3, 3, 3, 2, 1], | |
[1, 2, 3, 4, 4, 4, 4, 3, 2, 1], | |
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1], | |
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1], | |
[1, 2, 3, 4, 4, 4, 4, 3, 2, 1], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
#User function Template for python3 | |
#Complete this function | |
def findFloor(self,A,N,X): | |
#Your code here | |
nums = A | |
x = X | |
n = N | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int go(int[] a, int l, int r) { | |
if (l == r) | |
return a[l]; | |
int mid = (l + r) / 2; | |
return go(a, l, mid) + go(a, mid + 1, r); | |
} | |
int[] a = {...}; | |
int N = a.length; |