Submission #959206

# Submission time Handle Problem Language Result Execution time Memory
959206 2024-04-07T16:53:52 Z Ariadna Savez (COCI15_savez) C++14
0 / 120
1000 ms 45648 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> dp;
int solve(int i, int n, vector<string>& x) {
    if (dp[i] != -1) return dp[i];
    dp[i] = 1;
    bool control = true;
    for (int j = i+1; j < n && control; ++j) {
        if ((int)x[i].size() > (int)x[j].size()) continue;
        bool prefix = true, suffix = true;
        for (int k = 0; k < (int)x[i].size() && prefix; ++k) {
            if (x[j][k] > x[i][k]) {
                control = false;
                prefix = false;
            } else if (x[j][k] < x[i][k]) prefix = false;
        }
        if (!prefix) continue;
        for (int k = 0; k < (int)x[i].size() && suffix; ++k) {
            if (x[j][(int)x[j].size() - (int)x[i].size() + k] > x[i][k]) {
                suffix = false;
            } else if (x[j][(int)x[j].size() - (int)x[i].size() + k] < x[i][k]) suffix = false;
        }
        if (!suffix) continue;

        dp[i] = max(dp[i], 1 + solve(j, n, x));
    }
    return dp[i];
}

int main() {
    int n; 
    cin >> n;
    vector<string> x(n);
    dp = vector<int>(n, -1);
    for (int i = 0; i < n; ++i) cin >> x[i];

    sort(x.begin(), x.end());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (dp[i] == -1) ans = max(ans, solve(i, n, x));
    }
    cout << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 2 ms 604 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 247 ms 2340 KB Output is correct
2 Incorrect 246 ms 2344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 171 ms 1628 KB Output is correct
3 Incorrect 171 ms 1912 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 2640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 4184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1067 ms 6472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1024 ms 9556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 27472 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 45648 KB Time limit exceeded
2 Halted 0 ms 0 KB -