PS/BOJ57 백준 23878 / C++ https://www.acmicpc.net/problem/23878 23878번: Lonely Photo Farmer John has recently acquired $N$ new cows $(3 \le N \le 5 \times 10^5)$, each of whose breed is either Guernsey or Holstein. The cows are currently standing in a line, and Farmer John wants take a photo of every sequence of three or more consecutive c www.acmicpc.net [ 풀이 ] 아이디어는 쉽습니다. 연속된 G끼리, H끼리 묶어서 개수를 구해줍니다. 우선 연속된 G를 기준으로 세봅시다.. 2022. 8. 23. 백준 23877 / C++ https://www.acmicpc.net/problem/23877 23877번: Convoluted Intervals In this example, for just $k=3$, there are three ordered pairs that will allow Bessie and Elie to win: $(1, 1)$, $(1, 2),$ and $(2, 1)$. www.acmicpc.net [ 풀이 ] N제한에 비해 M은 5000이므로 O(M^2)까진 가능하다. 구하는 값은 ai+aj n >> m; for (int i = 0; i > x >> y; A[x]++, B[y]++; } for (int i = 0; i 2022. 8. 23. 백준 14958 / C++ https://www.acmicpc.net/problem/14958 14958번: Rock Paper Scissors There is a Rock Paper Scissors (RPS) machine which generates Rock, Paper, or Scissors randomly. You also have a similar small Rock Paper Scissors machine. Before the game, the RPS machine will generate a list of its choice of Rock, Paper, or Scissors of th www.acmicpc.net [ 풀이 ] 매번 옮겨가면서 계산하면 O(mn)이다. FFT로 합성곱 구하는 과정을 NlogN에 해주자. .. 2022. 8. 22. 백준 3037 / C++ https://www.acmicpc.net/problem/3037 3037번: 혼란 첫째 줄에 혼란도가 C이고 길이가 N인 수열의 개수를 1,000,000,007로 나눈 나머지를 출력한다. www.acmicpc.net [ 풀이 ] dp[i][j]를 1~i까지 혼란도가 j인 수열의 개수라고 정의하자. 1~i번 칸에서 수 i를 놓는 위치를 생각해보자. i를 k번 칸에 놓았다면, k+1칸~i번 칸에 의해 혼란도가 i-k개 증가한다. 따라서 i를 k번 칸에 놓을 때 혼란도가 j가 되려면 k번칸을 제외한 1~i-1에서 혼란도가 j-(i-k)가 되어야 한다. 따라서 식은 dp[i][j]=sum(dp[i-1][j-i+k])이다. 식을 더 개선해보자. dp[i][j]와 dp[i][j-1] 차를 구하면, dp[i-1][.. 2022. 8. 22. 이전 1 2 3 4 5 ··· 15 다음