Skip to content

Commit 17c7142

Browse files
committed
2021.01.27
1 parent 9803fcd commit 17c7142

File tree

5 files changed

+213
-0
lines changed

5 files changed

+213
-0
lines changed

python/kakao/2021_4.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
n, s, a, b = map(int,input().split())
5+
INF = 1e10
6+
fares = []
7+
tmp = []
8+
for idx,row in enumerate(list(map(str,input().split(',')))):
9+
row = row.replace("[","").replace("[","")
10+
row = row.replace("]","").replace("]","")
11+
if idx>1 and idx%3==0:
12+
fares.append(tmp)
13+
tmp = [int(row)]
14+
else:
15+
tmp.append(int(row))
16+
17+
adj = [[INF]*(n+1) for _ in range(n+1)]
18+
print(fares)
19+
for c,d,f in fares:
20+
adj[c][d]=f
21+
adj[d][c]=f
22+
23+
print("\n".join(map(str,adj)))
24+
for i in range(1,n+1):
25+
for j in range(1,n+1):
26+
for k in range(1,n+1):
27+
if i==j or j==k or i==k:continue
28+
if adj[i][k]+adj[k][j]<adj[i][j]:
29+
adj[i][j]=adj[i][k]+adj[k][j]
30+
ans = INF
31+
print("\n".join(map(str,adj)))
32+
for i in range(1,n+1):
33+
ans = min(ans,adj[s][i]+adj[i][a]+adj[i][b])
34+
print(ans)

python/kakao/2021_6.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import sys
2+
input = sys.stdin.readline
3+
def solution(sales, links):
4+
adj = [[] for _ in range(len(sales))]
5+
for a,b in links:
6+
adj[a-1].append(b-1)
7+
dp_arr = [[-1,-1] for _ in range(len(sales))]
8+
def dp(now,check):
9+
if len(adj[now])==0:
10+
return 0
11+
if dp_arr[now][check]!=-1:return dp_arr[now][check]
12+
#check True -> 팀원들 맘대로
13+
#check False -> 팀원이 다안가면 팀중에 최소매출인원 무조건 보냄
14+
res = 0
15+
if check:
16+
for nx in adj[now]:
17+
res+=min(dp(nx,False),dp(nx,True)+sales[nx])
18+
else:
19+
flag = False
20+
tmp = sales[now]
21+
for nx in adj[now]:
22+
m1 = dp(nx,False)
23+
m2 = dp(nx,True)+sales[nx]
24+
if m2<=m1:
25+
flag=True
26+
res+=m2
27+
else:
28+
if m2-m1<tmp:
29+
tmp = m2-m1
30+
res+=m1
31+
if not flag:
32+
res+=tmp
33+
dp_arr[now][check]=res
34+
return res
35+
answer = dp(0,False)
36+
return answer
37+
38+
r,c=map(int,input().split())
39+
40+
board = []
41+
tmp = []
42+
for idx,row in enumerate(list(map(str,input().split(',')))):
43+
row = row.replace("[","").replace("[","")
44+
row = row.replace("]","").replace("]","")
45+
if idx>1 and idx%4==0:
46+
board.append(tmp)
47+
tmp = [int(row)]
48+
else:
49+
tmp.append(int(row))
50+
board.append(tmp)
51+
print(solution(board,r,c))

python/plat3/1395.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys
2+
3+
input = sys.stdin.readline
4+
output = sys.stdout.write
5+
6+
N, M = map(int,input().split())
7+
8+
tree = [0]*(4*N)
9+
lazy = [0]*(4*N)
10+
11+
def propagate(node,now_s,now_e):
12+
if lazy[node]:
13+
tree[node]=(now_e-now_s+1)-tree[node]
14+
if now_s!=now_e:
15+
lazy[node<<1]^=1
16+
lazy[node<<1|1]^=1
17+
lazy[node]=0
18+
19+
def update(now_s,now_e,s,e,node):
20+
propagate(node,now_s,now_e)
21+
if now_s>e or now_e<s:return
22+
if s<=now_s and now_e<=e:
23+
tree[node]=(now_e-now_s+1)-tree[node]
24+
if now_s!=now_e:
25+
lazy[node<<1]^=1
26+
lazy[node<<1|1]^=1
27+
return
28+
mid = (now_e+now_s)>>1
29+
update(now_s,mid,s,e,node<<1)
30+
update(mid+1,now_e,s,e,node<<1|1)
31+
tree[node]=tree[node<<1] + tree[node<<1|1]
32+
33+
def query(now_s,now_e,s,e,node):
34+
propagate(node,now_s,now_e)
35+
if e<now_s or s>now_e:return 0
36+
if s<=now_s and now_e<=e:return tree[node]
37+
mid = (now_e+now_s)>>1
38+
return query(now_s,mid,s,e,node<<1)+query(mid+1,now_e,s,e,node<<1|1)
39+
40+
for _ in range(M):
41+
cmd, i, j = map(int,input().split())
42+
if cmd==0:
43+
update(1,N,i,j,1)
44+
else:
45+
output("%d\n"%query(1,N,i,j,1))
46+
#print(tree[:2*N])

python/plat3/1671.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
input = sys.stdin.readline
3+
output = sys.stdout.write
4+
5+
N = int(input())
6+
#상어 네트워크 그래프 만들고(먹는놈->먹힐놈)
7+
#이분탐색두번
8+
#N-이분탐색두번결과
9+
adj = [[] for _ in range(N)]
10+
arr = []
11+
def dfs(idx):
12+
visited[idx]=True
13+
for nx in adj[idx]:
14+
if p[nx]==-1 or (not visited[p[nx]] and dfs(p[nx])):
15+
p[nx]=idx
16+
return True
17+
return False
18+
19+
p = [-1]*N
20+
for j in range(N):
21+
a,b,c = map(int,input().split())
22+
for i,n in enumerate(arr):
23+
na,nb,nc = n
24+
if na<=a and nb<=b and nc<=c:
25+
adj[j].append(i)
26+
elif a<=na and b<=nb and c<=nc:
27+
adj[i].append(j)
28+
arr.append((a,b,c))
29+
ans = 0
30+
for i in range(N):
31+
visited = [False]*N
32+
if dfs(i):ans+=1
33+
for i in range(N):
34+
visited = [False]*N
35+
if dfs(i):ans+=1
36+
print(N-ans)

python/plat3/7469.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import sys
2+
import bisect
3+
input = sys.stdin.readline
4+
output = sys.stdout.write
5+
n, m = map(int,input().split())
6+
st = 1
7+
while st<n:
8+
st*=2
9+
tree = [[] for _ in range(4*n)]
10+
arr = list(map(int,input().split()))
11+
tmp = {}
12+
tmp2 = {}
13+
for i,x in enumerate(sorted(arr)):
14+
tmp[x]=i
15+
tmp2[i]=x
16+
for idx,num in enumerate(arr,st):
17+
tree[idx]=[tmp[num]]
18+
tmp = st
19+
while tmp>1:
20+
ed = tmp
21+
tmp = tmp//2
22+
for i in range(tmp,ed):
23+
left,right = 0,0
24+
l,r = len(tree[i<<1]),len(tree[i<<1|1])
25+
while left<l or right<r:
26+
if right==r or (left<l and tree[i<<1][left]<tree[i<<1|1][right]):
27+
tree[i].append(tree[i<<1][left])
28+
left+=1
29+
else:
30+
tree[i].append(tree[i<<1|1][right])
31+
right+=1
32+
def find(s,e,node,ns,ne,x):
33+
if ne<s or ns>e:return 0
34+
if s<=ns and ne<=e:return bisect.bisect_right(tree[node],x)
35+
mid = (ns+ne)>>1
36+
return find(s,e,node<<1,ns,mid,x) + find(s,e,node<<1|1,mid+1,ne,x)
37+
for _ in range(m):
38+
i,j,k = map(int,input().split())
39+
l,r = 0,n
40+
while l<=r:
41+
mid = (l+r)>>1
42+
if find(i,j,1,1,st,mid)<k:
43+
l=mid+1
44+
else:
45+
r=mid-1
46+
output("%d\n"%tmp2[l])

0 commit comments

Comments
 (0)