# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
100166 |
2019-03-09T18:11:21 Z |
pamaj |
Rima (COCI17_rima) |
C++14 |
|
100 ms |
36892 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 18;
int dp[1 << 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 mask)
{
if(dp[mask] != -1) return dp[mask];
int ans = 0;
for(int j = i + 1; j < n; j++)
{
if(i == -1)
{
ans = max(ans, solve(j, mask | (1 << j)) + 1);
}
else if(rhyme(s[i], s[j]))
{
ans = max(ans, solve(j, mask | (1 << j)) + 1);
}
}
return dp[mask] = ans;
}
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(-1, 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 |
2 ms |
1408 KB |
Output isn't correct |
2 |
Correct |
3 ms |
1408 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1408 KB |
Output isn't correct |
4 |
Runtime error |
100 ms |
36892 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Runtime error |
18 ms |
11384 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
6 |
Runtime error |
8 ms |
4720 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Runtime error |
7 ms |
4344 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
8 |
Runtime error |
9 ms |
4024 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
9 |
Runtime error |
26 ms |
13128 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Runtime error |
8 ms |
4188 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |