Submission #100173

# Submission time Handle Problem Language Result Execution time Memory
100173 2019-03-09T18:22:16 Z pamaj Rima (COCI17_rima) C++14
14 / 140
105 ms 41536 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5;

int dp[maxn], n;
vector<string> s;

bool rhyme(const string& a, const string& b)
{
	int u = a.size() - 1, v = b.size() - 1;

	int cont = 0;
	while(a[u] == b[v] and u >= 0 and v >= 0)
	{
		cont++, u--, v--;
	}

	if(cont >= max(a.size(), b.size()) - 1) return true;
	return false;
}

int solve(int i, int j)
{

	if(dp[i] != -1) return dp[i];

	if(i == n) return 0;

	int caso1 = solve(i + 1, j);
	int caso2;

	if(rhyme(s[i],s[j]))
	{
		caso2 = solve(i + 1, i) + 1;
	}
	else 
		caso2 = 0;


	return dp[i] = max(caso1, caso2);
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr);

	cin >> n;

	for(int i = 0; i < n; i++)
	{
		string a;
		cin >> a;
		s.push_back(a);
	}

	memset(dp, -1, sizeof(dp));

	cout << solve(0, 0) << "\n";
}

Compilation message

rima.cpp: In function 'bool rhyme(const string&, const string&)':
rima.cpp:19:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(cont >= max(a.size(), b.size()) - 1) return true;
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2304 KB Output isn't correct
2 Correct 3 ms 2304 KB Output is correct
3 Incorrect 4 ms 2304 KB Output isn't correct
4 Incorrect 105 ms 41536 KB Output isn't correct
5 Incorrect 14 ms 5376 KB Output isn't correct
6 Incorrect 6 ms 3056 KB Output isn't correct
7 Incorrect 6 ms 2936 KB Output isn't correct
8 Incorrect 5 ms 2872 KB Output isn't correct
9 Incorrect 20 ms 6736 KB Output isn't correct
10 Incorrect 6 ms 3036 KB Output isn't correct