diff --git "a/momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" "b/momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" new file mode 100644 index 0000000..83a874b --- /dev/null +++ "b/momnpa333/week10/[BOJ]1043-\352\261\260\354\247\223\353\247\220.py" @@ -0,0 +1,49 @@ +import sys +input=sys.stdin.readline + +N,M=map(int,input().split()) +lier=set(list(map(int,input().split()))[1:]) + +parents=[i for i in range(N+1)] + +groups=[] + +def findparents(i): + if i!=parents[i]: + parents[i]=findparents(parents[i]) + return parents[i] + return i + +def union(a,b): + a=findparents(a) + b=findparents(b) + if a in lier or b in lier: + lier.add(a) + lier.add(b) + + if a25 :A +#20->25: B +#30->25: C +#25->40: D +#그외 :S +Sboard=[[i,True] for i in range(0,40,2)] +Aboard=[[i,True] for i in range(10,22,3)] +Bboard=[[i,True] for i in range(20,26,2)] +Cboard=[[i,True] for i in range(28,25,-1)] +Dboard=[[i,True] for i in range(25,45,5)] + +#말->W,X,Y,Z +total_score={ + "W":0, + "X":0, + "Y":0, + "Z":0 +} + +def move_horse(horse,position,dice,total_score,Sboard,Aboard,Bboard,Cboard,Dboard): + if position[0]=="S": + if dice+position[1]>20: + Sboard[dice+position[1]][1]=True + return ("EXIT",total_score) + if dice+position[1]==5 and Aboard[0][1]==True: + total_score[horse]+=Aboard[0][0] + Sboard[position[1]][1]=True + Aboard[0][1]=False + return ("A",0,total_score) + if dice+position[1]==10 and Bboard[0][1]==True: + total_score[horse]+=Aboard[0][0] + Sboard[position[1]][1]=True + Bboard[0][1]=False + return ("B",0,total_score) + if dice+position[1]==15 and Cboard[0][1]==True: + total_score[horse]+=Aboard[0][0] + Sboard[position[1]][1]=True + Cboard[0][1]=False + return ("C",0,total_score) + if dice+position[1]==20 and Dboard[3][1]==True: + total_score[horse]+=Dboard[3][0] + Sboard[position[1]][1]=True + Dboard[3][1]=False + return ("D",3,total_score) + if Sboard[dice+position[1]][1]==True: + total_score[horse]+=Sboard[dice+position[1]][0] + Sboard[position[1]][1]=True + Sboard[dice+position[1]][1]=False + return ("S",dice+position[1],total_score) + return ("S",position[1],total_score) + if position[0]=="A": + next_position=dice+position[1] + if next_position>7: + Aboard[position[1]]=True + return ("EXIT",total_score) + if next_position>3: + next_position-=4 + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Aboard[position[1]][1]=True + return ("D",next_position,total_score) + if Aboard[next_position][1]==True: + total_score[horse]+=Aboard[next_position][0] + Aboard[next_position][1]=False + Aboard[position[1]]=True + return ("A",next_position,total_score) + if position[0]=="B": + next_position=dice+position[1] + if next_position>6: + Bboard[position[1]]=True + return ("EXIT",total_score) + if next_position>2: + next_position-=3 + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Bboard[position[1]][1]=True + return ("D",next_position,total_score) + if Bboard[next_position][1]==True: + total_score[horse]+=Bboard[next_position][0] + Bboard[next_position][1]=False + Bboard[position[1]]=True + return ("B",next_position,total_score) + if position[0]=="C": + next_position=dice+position[1] + if next_position>7: + Cboard[position[1]]=True + return ("EXIT",total_score) + if next_position>3: + next_position-=4 + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Cboard[position[1]][1]=True + return ("D",next_position,total_score) + if Cboard[next_position][1]==True: + total_score[horse]+=Cboard[next_position][0] + Cboard[next_position][1]=False + Cboard[position[1]]=True + return ("C",next_position,total_score) + if position[0]=="D": + next_position=dice+position[1] + if next_position>3: + Dboard[position[1]]=True + return ("EXIT",total_score) + if Dboard[next_position][1]==True: + total_score[horse]+=Dboard[next_position][0] + Dboard[next_position][1]=False + Dboard[position[1]]=True + return ("D",next_position,total_score) + return (position[0],position[1],total_score) + + +dq=deque([]) +dq.appendleft(({"W":("S",0),"X":("S",0),"Y":("S",0),"Z":("S",0)},total_score.copy(),copy.deepcopy(Sboard),copy.deepcopy(Aboard),copy.deepcopy(Bboard),copy.deepcopy(Cboard),copy.deepcopy(Dboard))) +round=0 +while dq: + if round==1: + break + for _ in range(len(dq)): + horses,total_score,Sboard,Aboard,Bboard,Cboard,Dboard=dq.popleft() + for horse in horses: + result=move_horse(horse,horses[horse],rolls[round],total_score,Sboard,Aboard,Bboard,Cboard,Dboard) + horse_status=horses.copy() + if result[0]=="EXIT": + del horse_status[horse] + dq.appendleft((horse_status,result[1],copy.deepcopy(Sboard),copy.deepcopy(Aboard),copy.deepcopy(Bboard),copy.deepcopy(Cboard),copy.deepcopy(Dboard))) + continue + horse_status[horse]=(result[0],result[1]) + dq.appendleft(((horse_status),result[2],copy.deepcopy(Sboard),copy.deepcopy(Aboard),copy.deepcopy(Bboard),copy.deepcopy(Cboard),copy.deepcopy(Dboard))) + round+=1 + +for item in dq: + print(item[0],item[1]) + + + diff --git a/momnpa333/week8/16928.py b/momnpa333/week8/16928.py new file mode 100644 index 0000000..279bb68 --- /dev/null +++ b/momnpa333/week8/16928.py @@ -0,0 +1,38 @@ +#100번 칸을 넘어간다면 이동할 수 없다. +#도착한 칸이 사다리면, 사다리를 타고 위로 올라간다. 뱀이 있는 칸에 도착하면, 뱀을 따라서 내려가게 된다. +#1번 칸과 100번 칸은 뱀과 사다리의 시작 또는 끝이 아니다. 모든 칸은 최대 하나의 사다리 또는 뱀을 가지고 있으며, 동시에 두 가지를 모두 가지고 있는 경우는 없다. 항상 100번 칸에 도착할 수 있는 입력만 주어진다. + +import sys +from collections import deque +input=sys.stdin.readline + +N,M=map(int,input().split()) +bridge=dict() +for _ in range(N+M): + u,v=map(int,input().split()) + bridge[u]=v + +dq=deque([]) +position=1 +check={1,} + +dq.append(1) + +count=0 + +while dq: + count+=1 + for _ in range(len(dq)): + pos=dq.popleft() + for i in range(1,7): + next=pos+i + if next in bridge: + next=bridge[next] + if next==100: + print(count) + exit(0) + if next<=100 and next not in check: + dq.append(next) + check.add(next) + + diff --git a/momnpa333/week8/2156.py b/momnpa333/week8/2156.py new file mode 100644 index 0000000..a555d4b --- /dev/null +++ b/momnpa333/week8/2156.py @@ -0,0 +1,23 @@ +import sys +input=sys.stdin.readline + +N=int(input()) + +wine=[] +for _ in range(N): + wine.append(int(input())) + +if N<3: + print(sum(wine)) + exit(0) + +dp=[0]*N + +dp[0]=wine[0] +dp[1]=dp[0]+wine[1] +dp[2]=max(dp[1],dp[0]+wine[2],wine[1]+wine[2]) + +for i in range(3,N): + dp[i]=max(dp[i-1],dp[i-2]+wine[i],dp[i-3]+wine[i-1]+wine[i]) + +print(dp[-1]) \ No newline at end of file diff --git a/momnpa333/week8/23288.py b/momnpa333/week8/23288.py new file mode 100644 index 0000000..dac9ee6 --- /dev/null +++ b/momnpa333/week8/23288.py @@ -0,0 +1,85 @@ +import sys +from collections import deque +input=sys.stdin.readline + +N,M,K=map(int,input().split()) +board=[list(map(int,input().split())) for _ in range(N)] + +diceRow=[2,1,5,6] +diceCol=[4,1,3,6] + +dir_dict={0:(0,1),1:(1,0),2:(0,-1),3:(-1,0)} + +def move_dice(op): + global diceCol + global diceRow + + if op==0: + diceCol=[diceCol[-1]]+diceCol[:3] + diceRow[-1]=diceCol[-1];diceRow[1]=diceCol[1] + elif op==1: + diceRow=[diceRow[-1]]+diceRow[:3] + diceCol[-1]=diceRow[-1];diceCol[1]=diceRow[1] + elif op==2: + diceCol=diceCol[1:]+[diceCol[0]] + diceRow[-1]=diceCol[-1];diceRow[1]=diceCol[1] + elif op==3: + diceRow=diceRow[1:]+[diceRow[0]] + diceCol[-1]=diceRow[-1];diceCol[1]=diceRow[1] + +def make_score_board(board): + scored_board=[[-1]*M for _ in range(N)] + dq=deque([]) + + + for r in range(N): + for c in range(M): + fill_position=[] + if scored_board[r][c]==-1: + fill_position.append((r,c)) + dq.appendleft((r,c,board[r][c])) + scored_board[r][c]=0 + cnt=1 + while dq: + for _ in range(len(dq)): + curR,curC,score=dq.popleft() + for addR,addC in ((0,1),(1,0),(0,-1),(-1,0)): + R=curR+addR;C=curC+addC + if 0<=Rboard[R][C]: + dir=(dir+1)%4 + elif diceRow[3]=S: + if right-left+1count: + answer=count + return + if on_lights==target: + if answer>count+1: + answer=count+1 + return + + if 1