fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(NULL);
  7.  
  8. string a, b;
  9. cin >> a >> b;
  10.  
  11. int n = a.length();
  12. int m = b.length();
  13.  
  14. vector<int> dp(m + 1, 0);
  15. int maxLength = 0;
  16.  
  17. for (int i = 1; i <= n; ++i) {
  18. vector<int> next_dp(m + 1, 0);
  19. for (int j = 1; j <= m; ++j) {
  20. if (a[i - 1] == b[j - 1]) {
  21. next_dp[j] = dp[j - 1] + 1;
  22. maxLength = max(maxLength, next_dp[j]);
  23. }
  24. }
  25. dp = next_dp;
  26. }
  27.  
  28. cout << maxLength << endl;
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
0