# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785924 | MilosMilutinovic | Rima (COCI17_rima) | C++14 | 1067 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: wxhtzdy
* created: 17.07.2023 21:06:38
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<vector<bool>> f(n, vector<bool>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int si = (int) s[i].size();
int sj = (int) s[j].size();
int ptr = 0;
while (ptr < min(si, sj) && s[i][si - ptr - 1] == s[j][sj - ptr - 1]) {
ptr += 1;
}
f[i][j] = f[j][i] = (ptr >= max(si, sj) - 1);
}
}
vector<vector<bool>> dp(1 << n, vector<bool>(n));
for (int i = 0; i < n; i++) {
dp[1 << i][i] = true;
}
for (int mask = 1; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) {
if (!dp[mask][i]) {
continue;
}
for (int j = 0; j < n; j++) {
if (mask >> j & 1) {
continue;
}
if (f[i][j]) {
dp[mask ^ (1 << j)][j] = true;
}
}
}
}
int ans = 0;
for (int mask = 0; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) {
if (dp[mask][i]) {
ans = max(ans, __builtin_popcount(mask));
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |