본문 바로가기

13

[백준 2015] 수들의 합 4 www.acmicpc.net/problem/2015 2015번: 수들의 합 4 첫째 줄에 정수 N과 K가 주어진다. (1 ≤ N ≤ 200,000, |K| ≤ 2,000,000,000) N과 K 사이에는 빈칸이 하나 있다. 둘째 줄에는 배열 A를 이루는 N개의 정수가 빈 칸을 사이에 두고 A[1], A[2], ..., A[N]의 순서로 www.acmicpc.net 누적합과 구간합을 알아야 하는 문제이다. 가끔 보이는 유형인데 볼 때마다 못 푼다...ㅠㅠㅠ eazymean.tistory.com/43 [알고리즘] Prefix Sum 구간 합/누적 합 알고리즘 prefix sum이란 구간 합을 의미한다. 예를 들어, int arr[5] = {10,20,30,40,50}; prefix sum은 prefix[i].. 2021. 1. 1.
[백준 1181] 단어 정렬 www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1≤N≤20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net map 소팅을 사용해봤다. 문제에서 모든 단어는 한번만 등장하게 조건을 걸어서 map을 사용하여 소팅을 진행했다. 맵을 소팅하는 방법은 맵을 벡터에 담아서 벡터를 소팅하는 것이다. 이 때 compare함수는 map의 자료형으로 소팅하면 된다. #include #include #include #include #define pp pair using namespace std; map mp; bool compare.. 2020. 11. 28.
[leetcode 454] 4Sum II Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make problem a bit easier, all A, B, C, D have same length of N where 0 ≤ N ≤ 500. All integers are in the range of -228 to 228 - 1 and the result is guaranteed to be at most 231 - 1. Example: Input: A = [ 1, 2] B = [-2,-1] C = [-1, 2] D = [ 0, 2] Output: .. 2020. 11. 14.
[leetcode 49] Group Anagrams Given an array of strings strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: strs = ["eat","tea","tan","ate","nat","bat"] Output: [["bat"],["nat","tan"],["ate","eat","tea"]] Example 2: Input: strs = [""] O.. 2020. 10. 30.