Skip to main content

18405경쟁적 전염

·107 words·1 min· loading

https://www.acmicpc.net/problem/18405

18405번: 경쟁적 전염첫째 줄에 자연수 N, K가 공백을 기준으로 구분되어 주어진다. (1 ≤ N ≤ 200, 1 ≤ K ≤ 1,000) 둘째 줄부터 N개의 줄에 걸쳐서 시험관의 정보가 주어진다. 각 행은 N개의 원소로 구성되며, 해당 위치www.acmicpc.net

ㅋㅋㅋㅋㅋㅋㅋ 정신똑바로차리고풀어야겠다

말도안되는부분에서실수했다.

그냥 bfs다 큐에 넣을때 바이러스 내림차순으로만 넣어주면된다.

import sysfrom collections import dequeinput=sys.stdin.readlinearr=[]
move=[[-1,0],[1,0],[0,-1],[0,1]]n,k=map(int,input().split())
virus=[[] for _ in range(k+1)]for i in range(n):
    tmp=[*map(int,input().split())]    arr.append(tmp)    for j in range(n):
        t=tmp[j]        if t!=0:            virus[t].append((i,j,0))           
s,x,y=map(int,input().split())q=deque()for vii in virus:    if vii:
        for vi in vii:            q.append(vi)def bfs():    while q:
        cx,cy,t=q.popleft()        if t==s:            print(arr[x-1][y-1])
            exit()        for dx,dy in move:            nx,ny=cx+dx,cy+dy
            if 0<=nx<n and 0<=ny<n and not arr[nx][ny]:                
                arr[nx][ny]=arr[cx][cy]                
                q.append((nx,ny,t+1))                            bfs()
print(arr[x-1][y-1])