답안 #100171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100171 2019-03-09T18:20:36 Z pamaj Rima (COCI17_rima) C++14
0 / 140
242 ms 263168 KB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e4;

int dp[maxn][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][j] != -1) return dp[i][j];

	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][j] = 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;
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 203 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Runtime error 198 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Runtime error 197 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
4 Runtime error 242 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Runtime error 188 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
6 Runtime error 197 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
7 Runtime error 185 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 188 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Runtime error 200 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
10 Runtime error 216 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)