알고리즘/백준 7

백준 Python - 14698 전생했더니 슬라임 연구자였던 건에 대하여 (Hard)

www.acmicpc.net/problem/14698 14698번: 전생했더니 슬라임 연구자였던 건에 대하여 (Hard) 각 테스트 케이스마다 슬라임을 끝까지 합성했을 때 청구될 비용의 최솟값을 1, 000, 000, 007로 나눈 나머지를 출력한다. 전기 에너지가 전혀 필요하지 않은 경우엔 1 을 출력한다. www.acmicpc.net import heapq import sys mod=1000000007 for _ in range(int(sys.stdin.readline())): n=int(sys.stdin.readline()) e=list(map(int, sys.stdin.readline().split())) ans=1 if n==1: print(1) continue q=[] for i in e: h..

알고리즘/백준 2021.02.15

백준 Python - 1316 그룹 단어 체커

aisiunme.github.io/algorithm/2018/08/13/baekjoon-group-word-checker-1316.md/ 백준 온라인 저지 - 그룹 단어 체커(1316) Baekjoon Problem #1316 - 조건에 맞는 단어를 찾는 문제 aisiunme.github.io Jun Lee 님의 글을 참고하였습니다. 우선 제 코드는 틀렸습니다. cnt=0 for _ in range(int(input())): w={} idx="" word=input() if len(word)==word.count(word[0]) and len(word)>2: continue for i in word: if (i not in w)or idx==i: w[i]=True else: w[i]=False idx=i..

알고리즘/백준 2021.02.14

백준 Python - 2941 크로아티아 알파벳

n=input() c=["c=","c-","dz=","d-","lj","nj","s=","z="] cnt=0 for i in c: if i in n: cnt+=n.count(i) n=n.replace(i," ") print(cnt+len(n.replace(" ",""))) 입력 크로아티아 알파벳 리스트 생성 알파벳 리스트를 돌며 입력한 문자열(n)검색 몇개 있는지 카운트(cnt+)하고 replace로 몽땅 빈 칸으로 변경-> 공백을 없애버리면 이전 문자와 다음 문자가 붙어서 크로아티아 알파벳으로 인식해버린다. cnt 값 + 빈 칸 제거한 n의 길이의 합을 구하면 된다. 내 풀이가 영 찝찝해서 다른 사람의 풀이를 찾아보았다. (실수로 아이디를 확인 못했습니다.) t=input() for i in ['c='..

알고리즘/백준 2021.02.12

순열과 조합 정복하기! 백준 15649~15666번

www.acmicpc.net/workbook/view/2052 문제집: N과 M (시리즈) www.acmicpc.net itertools 사용 1) 순열 from itertools import permutations as p n,m=map(int,input().split()) for i in p(range(1,n+1),m): print(*i) 2) 조합 from itertools import combinations as p n,m=map(int,input().split()) for i in p(range(1,n+1),m): print(*i) 3) 중복 순열 from itertools import product as p n,m=map(int,input().split()) for i in p(range(1,..

알고리즘/백준 2021.02.10

백준 Python - 1931 회의실 배정

import sys n=int(sys.stdin.readline()) arr1=list(map(int,sys.stdin.readline().split())) cnt=1 for i in range(n-1): arr2=list(map(int,sys.stdin.readline().split())) if arr1[1]= 0 이므로 조건문에 부합하면 arr1=arr2 해준다. 어디서 틀린 거지? --- 입력받은대로 횟수를 구하는게 아니라 모든 입력에 대해서 최대 사용 가능 횟수를 구하는 거다. 문제를 제대로 못 봤다. 이렇게 되면 끝나는 시간을 기준으로 우선 정렬을 한 뒤 시작 시간으로 정렬해준다. 왜냐하면 10 15 1 5 5 10 이렇게 있을 때 이대로 결과를 내면 회의가 1회 밖에 못하지만 정렬을 하면 1 ..

알고리즘/백준 2021.02.10

백준 Python - 11399 ATM

www.acmicpc.net/problem/11399 11399번: ATM 첫째 줄에 사람의 수 N(1 ≤ N ≤ 1,000)이 주어진다. 둘째 줄에는 각 사람이 돈을 인출하는데 걸리는 시간 Pi가 주어진다. (1 ≤ Pi ≤ 1,000) www.acmicpc.net 코드: n=int(input()) arr=list(map(int,input().split())) arr.sort() p=[] for i in range(1,n+1): p.append(sum(arr[:i])) print(sum(p)) 풀이: 테스트 케이스 , 시간을 입력받고 arr은 최소 시간을 구하기 위해서 정렬시킨다. 개인별로 소요되는 시간 Pi를 담을 빈 리스트 p 를 생성한다. arr에는 시간 순으로 나열되어 있으므로 for 문으로 하..

알고리즘/백준 2021.02.08