Search
Duplicate
🍋

공통 부분 문자열

주차
13
문제번호
5582
언어
티어
골드
유형
DP
nj_Blog
nj_상태
이해도
풀이
풀이 X
사람
13 more properties

Memo

문자열 앞에 0을 넣어줘야하는 것을 놓쳤었음!

Code

제출 날짜

@3/27/2021

메모리

64792 KB

시간

96 ms
// 5582 번 #include <algorithm> #include <iostream> #include <vector> int max; std::string a; std::string b; std::vector<std::vector<int> > dp; void output() { std::cout << max; } void solution() { for (size_t i = 1 ; i < a.size() ; i++) { for(size_t j = 1 ; j < b.size() ; j++) { if (a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1] + 1; } if (max < *std::max_element(dp[i].begin(), dp[i].end())) max = *std::max_element(dp[i].begin(), dp[i].end()); } } void input() { std::cin >> a >> b; a = "0" + a; b = "0" + b; dp = std::vector(a.size(), std::vector(b.size(), 0)); } void preset() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); } int main(void) { preset(); input(); solution(); output(); }
C++
복사