# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1006379 | MilosMilutinovic | Rima (COCI17_rima) | C++14 | 135 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.
#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];
}
for (int i = 0; i < n; i++) {
reverse(s[i].begin(), s[i].end());
}
auto Can = [&](string s, string t) {
if (s.size() > t.size()) {
swap(s, t);
}
int p = 0;
while (p < (int) s.size() && s[p] == t[p]) {
p += 1;
}
return p >= (int) t.size() - 1;
};
vector<vector<bool>> good(1 << n, vector<bool>(n));
for (int i = 0; i < n; i++) {
good[1 << i][i] = true;
}
for (int mask = 1; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) {
if ((mask >> i & 1) && good[mask][i]) {
for (int j = 0; j < n; j++) {
if (mask >> j & 1) {
continue;
}
if (Can(s[i], s[j])) {
good[mask | (1 << j)][j] = true;
}
}
}
}
}
int res = 0;
for (int mask = 0; mask < (1 << n); mask++) {
for (int i = 0; i < n; i++) {
if (mask >> i & 1) {
if (good[mask][i]) {
res = max(res, __builtin_popcount(mask));
}
}
}
}
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |