Submission #1056998

# Submission time Handle Problem Language Result Execution time Memory
1056998 2024-08-13T12:59:43 Z albinoATojuz Round words (IZhO13_rowords) C++14
28 / 100
17 ms 21868 KB
#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

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 time Memory Grader output
1 Incorrect 0 ms 484 KB Output isn't correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 1884 KB Output is correct
7 Correct 10 ms 15964 KB Output is correct
8 Incorrect 11 ms 15964 KB Output isn't correct
9 Incorrect 12 ms 15964 KB Output isn't correct
10 Incorrect 15 ms 15964 KB Output isn't correct
11 Incorrect 14 ms 17500 KB Output isn't correct
12 Correct 13 ms 20544 KB Output is correct
13 Incorrect 17 ms 20316 KB Output isn't correct
14 Incorrect 15 ms 18268 KB Output isn't correct
15 Incorrect 17 ms 21868 KB Output isn't correct
16 Incorrect 13 ms 17712 KB Output isn't correct
17 Incorrect 10 ms 13256 KB Output isn't correct
18 Correct 16 ms 20880 KB Output is correct
19 Incorrect 12 ms 15964 KB Output isn't correct
20 Incorrect 15 ms 18524 KB Output isn't correct
21 Incorrect 3 ms 4188 KB Output isn't correct
22 Incorrect 6 ms 7260 KB Output isn't correct
23 Correct 9 ms 10304 KB Output is correct
24 Incorrect 8 ms 10844 KB Output isn't correct
25 Incorrect 15 ms 14336 KB Output isn't correct