# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
107730 | ahmad_salah | Savez (COCI15_savez) | C++17 | 1078 ms | 44108 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;
const int M = 1e6;
vector<string> v;
int n, memo[M] = {};
bool check(string s1, string s2) {
if (s2.size() < s1.size())
return false;
for (int i = 0; i < s1.size(); i++)
if (s1[i] != s2[i])
return false;
while (!s1.empty()) {
if (s1.back() != s2.back())
return false;
s1.pop_back();
s2.pop_back();
}
return true;
}
int solve(int i) {
int &r = memo[i];
if (!r) {
r = 1;
for (int j = i + 1; j < n; j++) {
if (check(v[i], v[j]))
r = max(r, 1 + solve(j));
}
}
return r;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int ans = 0;
cin >> n;
while (n--) {
string s;
cin >> s;
v.push_back(s);
}
n = v.size();
for (int i = 0; i < n; i++)
ans = max(ans, solve(i));
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |