Submission #1056998

#TimeUsernameProblemLanguageResultExecution timeMemory
1056998albinoATojuzRound words (IZhO13_rowords)C++14
28 / 100
17 ms21868 KiB
#include <bits/stdc++.h>

using namespace std;

class Solution {
  public:
	int longestCommonSubsequence(string a, string b) {
		int dp[a.size()][b.size()];
		for (int i = 0; i < a.size(); i++) { fill(dp[i], dp[i] + b.size(), 0); }
		for (int i = 0; i < a.size(); i++) {
			if (a[i] == b[0]) dp[i][0] = 1;
			if (i != 0) dp[i][0] = max(dp[i][0], dp[i - 1][0]);
		}
		for (int i = 0; i < b.size(); i++) {
			if (a[0] == b[i]) dp[0][i] = 1;
			if (i != 0) dp[0][i] = max(dp[0][i], dp[0][i - 1]);
		}
		for (int i = 1; i < a.size(); i++) {
			for (int j = 1; j < b.size(); j++) {
				if (a[i] == b[j]) {
					dp[i][j] = dp[i - 1][j - 1] + 1;
				} else {
					dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
				}
			}
		}
		return dp[a.size() - 1][b.size() - 1];
	}
};

int main () {
	
	string a,b,c,d;
	cin >> a >> b;
	c = a + a;
	d = b + b;
	Solution s;
	cout << s.longestCommonSubsequence(c,d) - s.longestCommonSubsequence(a,b) << "\n";
	
	
	return 0;
}

Compilation message (stderr)

rowords.cpp: In member function 'int Solution::longestCommonSubsequence(std::string, std::string)':
rowords.cpp:9:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |   for (int i = 0; i < a.size(); i++) { fill(dp[i], dp[i] + b.size(), 0); }
      |                   ~~^~~~~~~~~~
rowords.cpp:10:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |   for (int i = 0; i < a.size(); i++) {
      |                   ~~^~~~~~~~~~
rowords.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for (int i = 0; i < b.size(); i++) {
      |                   ~~^~~~~~~~~~
rowords.cpp:18:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   for (int i = 1; i < a.size(); i++) {
      |                   ~~^~~~~~~~~~
rowords.cpp:19:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |    for (int j = 1; j < b.size(); j++) {
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...