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
import sys | |
input = sys.stdin.readline | |
s1=input().strip() | |
s2=input().strip() | |
dp=[[0 for _ in range(len(s2)+1)] for _ in range(len(s1)+1)] | |
for i in range(1,len(s1)+1): | |
for j in range(1,len(s2)+1): | |
if s1[i-1] == s2[j-1]: | |
dp[i][j]=dp[i-1][j-1]+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
import sys | |
n,K=map(int,sys.stdin.readline().split()) | |
k=0 | |
people=[i+1 for i in range(n)] | |
print('<',end='') | |
for _ in range(n-1): | |
idx=(k+K-1)%len(people) | |
print(f'{people.pop(idx)}, ',end='') | |
k=idx%len(people) | |
print(f'{people.pop()}>') |
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
Grid=[[0 for _ in range(n)] for _ in range(m)] | |
visited=[[False for _ in range(n)] for _ in range(m)] | |
count=0 | |
for _ in range(k): | |
x,y=map(int,sys.stdin.readline().split()) | |
Grid[x][y]=1 | |
for i in range(m): | |
for j in range(n): | |
if Grid[i][j] and not visited[i][j]: | |
count+=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
import sys | |
input=sys.stdin.readline | |
n,m = map(int,input().split()) | |
trees=list(map(int,input().split())) | |
start, end = 0, max(trees) | |
result = 0 | |
while start <= end: | |
mid = (start + end) // 2 | |
cur_m = sum(x - mid for x in trees if x > mid) |
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
import sys | |
from collections import deque | |
input = sys.stdin.readline | |
n,k=map(int,input().split()) | |
if n>=k: | |
print(n-k) | |
else: | |
queue=deque() | |
dist=[100002] * 100001 | |
dist[n]=0 |