목록2024/09 (43)
넘치게 채우기
https://leetcode.com/problems/sum-of-prefix-scores-of-strings/description/?envType=daily-question&envId=2024-09-25leetcode - Sum of Prefix Scores of Strings문제 유형 : 트라이(Trie), 구현문제 난이도 : Hard 문제You are given an array words of size n consisting of non-empty strings.We define the score of a string word as the number of strings words[i] such that word is a prefix of words[i].For example, if words = ..
https://www.acmicpc.net/problem/1080BOJ - 1080: 행렬문제 유형 : 행렬, 그리디, 비트마스크문제 난이도 : Silver I 문제0과 1로만 이루어진 행렬 A와 행렬 B가 있다. 이때, 행렬 A를 행렬 B로 바꾸는데 필요한 연산의 횟수의 최솟값을 구하는 프로그램을 작성하시오.행렬을 변환하는 연산은 어떤 3×3크기의 부분 행렬에 있는 모든 원소를 뒤집는 것이다. (0 → 1, 1 → 0) 입력첫째 줄에 행렬의 크기 N M이 주어진다. N과 M은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에는 행렬 A가 주어지고, 그 다음줄부터 N개의 줄에는 행렬 B가 주어진다. 출력첫째 줄에 문제의 정답을 출력한다. 만약 A를 B로 바꿀 수 없다면 -1을 출력한다. 풀이이 ..
https://leetcode.com/problems/find-the-length-of-the-longest-common-prefix/description/?envType=daily-question&envId=2024-09-24leetcode - Find the Length of the Longest Common Prefix문제 유형 : 트라이(Trie), 문자열 처리, 해시문제 난이도 : Medium 문제You are given two arrays with positive integers arr1 and arr2.A prefix of a positive integer is an integer formed by one or more of its digits, starting from its leftmos..
https://www.acmicpc.net/problem/28360BOJ - 양동이 게임문제 유형 : 그리디, 그래프문제 난이도 : Silver I 문제찬우는 천하제일 코딩대회 참가자들과 간단한 게임을 하기로 했다. 게임은 '양동이 게임'으로, 맨 위의 양동이에 물을 100$만큼 부어 흘려보냈을 때 최종적으로 가장 많은 물이 담긴 양동이를 선택하면 이기는 게임이다. 양동이를 고르기 전까지는 연결 상태를 알 수 없다. 하지만 찬우는 양동이들이 어떻게 연결되어 있는지 이미 알고 있는 상태였다! 찬우가 게임을 이기기 위해서 골라야 하는 양동이에는 얼마만큼의 물이 들어있는지 알아보자. 1번 양동이가 항상 맨 위에 있으며, 1의 양만큼 물이 채워져 있는 양동이에 K>0개의 나가는 방향 호스가 연결되어 있으면 양동..
https://leetcode.com/problems/extra-characters-in-a-string/description/?envType=daily-question&envId=2024-09-23leetcode - Extra Characters in a String문제 유형 : 문자열 처리, 재귀, dp문제 난이도 : Medium 문제You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some ex..
https://leetcode.com/problems/k-th-smallest-in-lexicographical-order/description/?envType=daily-question&envId=2024-09-22leetcode - K-th Smallest in Lexicographical Order문제 유형 : 트리, dfs, 수학문제 난이도 : Hard 문제Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n]. 두 개의 정수 n과 k가 주어진다. 범위 [1,n]에서 사전순으로 k번째로 작은 정수를 반환하시오. 풀이순차적으로 k개를 찾는 것은 느리다.대신, 점프를 할 필요가 있다..
https://www.acmicpc.net/problem/21558BOJ - 전쟁 준비하기문제 유형 : 구현, 수학, 그리디문제 난이도 : Silver I 문제이번에 폴리매스 왕국은 이웃 나라인 사이언스보드를 정복하기 위해 전쟁을 치르려고 합니다. 당신은 전쟁에서 사용할 방진을 짜 달라는 부탁을 받아 방진을 연구하고 있습니다.전쟁 지역의 지형상 가장 효율적인 방진은 직사각형 구조일 것으로 보입니다.즉 X행Y열의 직사각형을 정확히 XY명의 병사가 채우고 있는 형태를 말합니다. 병사의 수가 정확히 떨어지지 않아 몇 명이 남거나 부족한 경우에는 이러한 방진을 짤 수 없습니다.폴리매스 문명은 예전에도 강력한 군사력으로 주변의 약소국을 다수 복속시켰으므로, 군대에도 서로 다른N개의 민족이 섞여 있습니다. 특히, ..
https://leetcode.com/problems/lexicographical-numbers/description/?envType=daily-question&envId=2024-09-21leetcode - Lexicographical Numbers문제 유형 : 수학, 구현, dfs, 재귀문제 난이도 : Medium 문제Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.You must write an algorithm that runs in O(n) time and uses O(1) extra space. 정수 n이 주어진다. [1, n]의 모든 숫자들을 사전순으로 정렬하여 반환하시..
https://www.acmicpc.net/problem/4531BOJ - Verdis Quo문제 유형 : 문자열 처리, 구현문제 난이도 : Silver I 문제로마인들은 알파벳의 일곱 문자를 통해서 수를 표현했다. 다음은 문자와 그에 대응하는 값을 보여주는 표이다.I = 1V = 5X = 10L = 50C = 100D = 500M = 1000이 7개의 숫자와 다음 규칙들을 통해서, 로마인들은 원하는 모든 수를 적을 수 있었다.만약에 주어지는 숫자들이 감소순으로 좌에서 우로 적혀있다면, 덧셈법칙을 쓸 수 있다. 예를 들어, 로마숫자 MMCLVII는 1000 + 1000 + 100 + 50 + 5 + 1 + 1 = 2157이다.이는 로마숫자를 지나치게 길게 하는 단점이 있어 뺄셈법칙 역시 존재한다. 만약에..
https://leetcode.com/problems/shortest-palindrome/description/?envType=daily-question&envId=2024-09-20leetcode - Shortest Palindrome문제 유형 : 팰린드롬, 문자열 처리, KMP 알고리즘문제 난이도 : Hard 문제You are given a string s. You can convert s to a palindrome by adding characters in front of it.Return the shortest palindrome you can find by performing this transformation. 문자열 s를 받는다. 당신은 s에 접두사를 붙여서 변환시킬 수 있다.s에 문자를 ..