IT 61

[acmicpc] 20057. 마법사 상어와 토네이도(python)

가운데 칸부터 2쌍씩 짝을 지어 증가된다. -> 2쌍씩 : for문 range 2까지 설정 import sys input=sys.stdin.readline N=int(input()) arr=[list(map(int,input().split())) for _ in range(N)] src_r,src_c=N//2,N//2 dirs=[(0,-1),(1,0),(0,1),(-1,0)] num=1 idx=0 def rotate_90(rate): return list(reversed(list(zip(*rate)))) rate=[[0,0,0.02,0,0], [0,0.1,0.07,0.01,0], [0.05,0,0,0,0], [0,0.1,0.07,0.01,0], [0,0,0.02,0,0]] rate2=rotate_90(r..

IT/coding study 2023.02.05

[acmicpc] 10816. 숫자 카드 2(python)

[이분탐색] 사전에 숫자 개수 먼저 구해 놓기 - 아이디어 참고 import sys from collections import defaultdict input=sys.stdin.readline N=int(input()) arr=list(map(int,input().split())) M=int(input()) brr=list(map(int,input().split())) count=defaultdict(int) for a in arr: count[a]+=1 arr.sort() for b in brr: left,right=0,N-1 answer=0 while leftb: right=mid-1 else: left=mid+1 print(answer,end=" ") https://www.acmicpc.net/pr..

IT/coding study 2022.11.11

web assembly 메모리 사용기

1. ArrayBuffer(binary array)를 이용해 Javascript와 Web assembly간의 데이터를 간편하게 읽고, 쓸 수 있다. 이는 배열에 대한 포인터 값으로 접근하여 가능해진다. 1) ArrayBuffer let buffer = new ArrayBuffer(16); // 연속된 16 byte 메모리 공간을 생성함. let view = new Uint32Array(buffer);//typedArray로 32bit씩 나눔=>4개로 나눠짐 view.set([1, 2, 3], 0); // typedArray의 set method를 사용하여 여러 값들을 저장. 포인터로 접근 가능 wasm을 생성할 때 glue code(js)도 함께 생성하면 glue code 내에 아래와 같이 알아서 메모리..

IT/web assembly 2022.10.12

[acmicpc] 2206. 벽 부수고 이동하기(python)

최단 경로 - bfs 이용 3차원 배열을 사용하여 풀었다. visit[row][col][0] : 방문한 길 중에 벽을 부순 적이 있는 경우 visit[row][col][1] : 방문한 길 중에 벽을 부순 적이 없는 경우 from collections import deque import sys input=sys.stdin.readline N,M=map(int,input().split()) arr=[list(input().strip()) for _ in range(N)] visit=[[[0]*2 for _ in range(M)] for _ in range(N)] dirs=[(1,0),(0,1),(-1,0),(0,-1)] q=deque() visit[0][0][1]=1 q.append((0,0,1)) def ..

IT/coding study 2022.10.10

[acmicpc] 21921. 블로그 (python)

n^2으로 하면 터져서 누적합으로 구현 import sys input=sys.stdin.readline N,X=map(int,input().split()) visit=list(map(int,input().split())) if sum(visit)==0: print('SAD') else: dp=[0]*N dp[0]=visit[0] for i in range(1,N): dp[i]=dp[i-1]+visit[i] if i>=X: dp[i]-=visit[i-X] maxNum=max(dp) print(maxNum) print(dp.count(maxNum)) https://www.acmicpc.net/problem/21921 21921번: 블로그 첫째 줄에 $X$일 동안 가장 많이 들어온 방문자 수를 출력한다. 만약..

IT/coding study 2022.10.04