From 63ad7d6983d4b993d1910729ec0346142d10c847 Mon Sep 17 00:00:00 2001 From: jo Date: Tue, 19 Mar 2024 19:50:46 +0900 Subject: [PATCH 1/3] =?UTF-8?q?BOJ9461=5F=ED=8C=8C=EB=8F=84=EB=B0=98=5F?= =?UTF-8?q?=EC=88=98=EC=97=B4=5F=EC=8B=A4=EB=B2=843=5F=EC=A1=B0=EC=9E=AC?= =?UTF-8?q?=EC=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2\2043_\354\241\260\354\236\254\354\235\200.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "study/baekjoon/week7/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" diff --git "a/study/baekjoon/week7/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" "b/study/baekjoon/week7/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" new file mode 100644 index 0000000..387a810 --- /dev/null +++ "b/study/baekjoon/week7/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264/BOJ9461_\355\214\214\353\217\204\353\260\230_\354\210\230\354\227\264_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" @@ -0,0 +1,14 @@ +P = [0 for i in range(101)] # 1 <= N <= 100 + +P[1] = 1 +P[2] = 1 +P[3] = 1 + +# P[N] = P[N-3] + P[N-2] 규칙 성립 +for i in range(4, 100+1): + P[i] = P[i-3] + P[i-2] + +t = int(input()) +for _ in range(t): + n = int(input()) + print(P[n]) \ No newline at end of file From d6f97f1a7be48df9ea786ee30e434b5466ef6561 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 25 Mar 2024 22:44:02 +0900 Subject: [PATCH 2/3] =?UTF-8?q?BOJ29515=5F=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=5F=EC=B0=BE=EA=B8=B0=5F=EC=8B=A4=EB=B2=843=5F?= =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3_\354\241\260\354\236\254\354\235\200.py" | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 "study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" diff --git "a/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" "b/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" new file mode 100644 index 0000000..06ed721 --- /dev/null +++ "b/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" @@ -0,0 +1,27 @@ +import math + +# n: 비밀번호의 자릿수, m: 비밀번호에 대해 기억하는 정보의 수 +n, m = map(int, input().split()) + +# x: 비번 입력하는 데 걸리는 시간, y: 비번 3번 연속 실패 입력 시 비번 입력할 수 없는 시간 +x, y = map(int, input().split()) + +pwCnt = 0 +cnt = 0 + +for _ in range(m): + # m개 줄에 걸쳐 비밀번호에 대한 정보를 뜻하는 a, b + a, b = map(int, input().split()) + if a != 0: # a가 0이 아니면, a번째 자리의 값이 b라는 것을 의미 + pwCnt += 1 + else: # a가 0이면 비번 중 한 자리의 값이 b라는 것을 의미 + cnt += 1 + +n -= pwCnt +result = 1 +if cnt > 0: + result *= math.comb(n,cnt) * math.factorial(cnt) +n -= cnt +if n > 0: + result *= math.perm(9-(pwCnt+cnt), n) +print(result * x + ((result -1) // 3) * y) \ No newline at end of file From 2c98d2de0d459d38019acd773bf4001dd37b8966 Mon Sep 17 00:00:00 2001 From: jojaegu2 <65579171+jojaegu2@users.noreply.github.com> Date: Tue, 26 Mar 2024 11:19:23 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Update=20BOJ29515=5F=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=5F=EC=B0=BE=EA=B8=B0=5F=EC=8B=A4=EB=B2=843?= =?UTF-8?q?=5F=EC=A1=B0=EC=9E=AC=EC=9D=80.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...43_\354\241\260\354\236\254\354\235\200.py" | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git "a/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" "b/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" index 06ed721..9aa69e9 100644 --- "a/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" +++ "b/study/baekjoon/week8/BOJ29715_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260/BOJ29515_\353\271\204\353\260\200\353\262\210\355\230\270_\354\260\276\352\270\260_\354\213\244\353\262\2043_\354\241\260\354\236\254\354\235\200.py" @@ -6,8 +6,8 @@ # x: 비번 입력하는 데 걸리는 시간, y: 비번 3번 연속 실패 입력 시 비번 입력할 수 없는 시간 x, y = map(int, input().split()) -pwCnt = 0 -cnt = 0 +pwCnt = 0 # 비밀번호의 특정 자리가 확정된 숫자의 개수입니다. +cnt = 0 # 비밀번호에 포함되어야 하지만 자리가 확정되지 않은 숫자의 개수 for _ in range(m): # m개 줄에 걸쳐 비밀번호에 대한 정보를 뜻하는 a, b @@ -17,11 +17,19 @@ else: # a가 0이면 비번 중 한 자리의 값이 b라는 것을 의미 cnt += 1 -n -= pwCnt +n -= pwCnt # 확정된 자리의 숫자를 제외한 남은 자리수를 업데이트 result = 1 if cnt > 0: + # n개의 자리 중에서 cnt개의 특정 숫자를 포함하는 조합의 수를 계산 + # cnt개의 특정 숫자를 나열하는 순열의 수를 계산합니다. result *= math.comb(n,cnt) * math.factorial(cnt) -n -= cnt + +n -= cnt # 자리는 확정되지 않았지만 포함되어야 하는 숫자를 배치한 후의 남은 자리수를 업데이트 if n > 0: + # 남은 자리수에 대해, 사용할 수 있는 숫자로 만들 수 있는 순열의 수를 계산합니다. + # 여기서 9 - (pwCnt + cnt)는 아직 사용되지 않은 숫자의 개수 (0 ~9번까지에서 -1) result *= math.perm(9-(pwCnt+cnt), n) -print(result * x + ((result -1) // 3) * y) \ No newline at end of file + +# 계산된 비밀번호 조합의 수에 따라 비밀번호를 입력하는 데 걸리는 +# 총 시간(result * x)과, 3회 연속 실패 후 대기하는 시간을 포함한 총 시간을 계산하고 출력 +print(result * x + ((result -1) // 3) * y)