![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FmafjS%2FbtsrEpL9AtS%2FfktoStKYVY2TlnrjcK1PrK%2Fimg.png)
Level 2. 유사 칸토어 비트열 너무 어려운 수학 문제.. 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include using namespace std; int f(int n, long long x) { if (n == 1 || f(n - 1, x / 5)) return (x % 5) != 2; else return 0; } int solution(int n, long long l, long long r) { int answer = 0; for (long long i = l - 1; i < r; ++i) answer += f(n, i); retu..
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcktZkW%2FbtsrxONrh9i%2FBOWkVJXLrYPedQ9F1tSaqK%2Fimg.png)
Level 2. 숫자 카드 나누기 우선, 원소의 범위가 크므로 단순 반복문을 사용하면 시간 초과가 발생할 것이다. 약수를 구하는 것은 유클리드 호제법을 사용하면 된다. GCD(a, b) = GCD(b, (a % b)) a, b의 대소관계는 상관 없다. GCD(a, b, c) = GCD(GCD((a, b), c)이다. 이 문제는 그냥 각 배열의 최대공약수를 구하고, 조건에 맞는 큰 수를 반환하면 된다. 문제에서는 마치 최대 공약수를 구하고도, 그 최대 공약수의 약수 중에서 조건에 맞는 것을 찾아야 하는 것처럼 나와 있다. 하지만, 최대 공약수로 나누어 떨어지는 데 그 약수로 나누어 떨어지지 않는 경우는 존재할 수 없다. #include #include #include using namespace std; ..
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FViqQo%2Fbtsro8MeZ06%2FQkg9nnikYTIFpFPtB4Vns0%2Fimg.png)
Level 2. 택배 배달과 수거하기 이동 경로를 최소화하기 위해서는 가장 먼 곳부터 배달과 수거를 마쳐야 한다. 배달과 수거를 각각 진행하면서 가장 먼 집을 유지하고, 가장 먼 집까지의 거리를 더하는 방식으로 진행한다. 카카오 문제 치고는 파싱이나 다양한 개념들이 섞여있진 않은데, 그렇다고 구현이 마냥 쉽지도 않았다. #include #include #include using namespace std; long long solution(int cap, int n, vector deliveries, vector pickups) { long long answer = 0; int ed = n - (find_if(deliveries.rbegin(), deliveries.rend(), [](int num) { ..
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2F01Fa0%2FbtsrqwZ8Fk1%2FTscvubdAp1Ey97CqUw1k6k%2Fimg.png)
Level 2. 숫자 블록 10,000,000 이하의 가장 큰 약수를 찾는 문제다. 수의 제곱근까지만 순회하면 되고, 약수와 수/약수를 최댓값을 구하는 데 사용하면 된다. #include #include #include #include using namespace std; int max_divisor(int num) { if (num
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FrWKWr%2Fbtsq1Je2NfS%2FbB5xjz1l2NB4gSwddShpq1%2Fimg.png)
Level 2. 요격 시스템 Level 3. 단속카메라와 정확히 같은 문제다. 새로운 구간으로 넘어갈지 검사할 때 =을 붙이는 것만 다르다. 구간이 나온다면 항상 시작점을 기준으로 정렬해 생각하면 된다. 두 구간이 겹치는 경우가 대부분이지만, 구간을 완전히 포함하는 경우도 있으므로 끝점을 최솟값으로 갱신해주어야 한다. #include #include #include #include using namespace std; struct Section { int start; int end; friend bool operator B.start; } }; int solution(vector targets) { i..
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbQNHgC%2FbtsqLSpoPDv%2FkK2y8fkwbdDIhOwkwVZB0K%2Fimg.png)
Level 2. 순위 검색 레벨 2가 맞나 싶을 정도로 파싱, 해시, 이진 탐색 그리고 효율성까지 정말 다양한 것들을 잘 알고 활용해야 하는 카카오 문제다. 꽤 어려웠지만 나름 성장했다고 느낀다. 우선 첫 번째 시도에서 시간 초과가 발생했다. 파싱은 정규 표현식을 이용해 and를 없애고 istringstream을 이용했다. 이후 언어부터 점수까지 조건에 맞는 인덱스를 구하는 방식으로 해결했다. [0, 1, 2, 3, 4, 5, 6, 7] [0, 2, 3, 5, 7] [0, 5, 7] [0, 5] [5] // 이 풀이는 시간 초과가 발생한다. #include #include #include #include #include #include using namespace std; enum class LANG {..