Submission #107730

# Submission time Handle Problem Language Result Execution time Memory
107730 2019-04-25T14:59:52 Z ahmad_salah Savez (COCI15_savez) C++17
24 / 120
1000 ms 44108 KB
#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

savez.cpp: In function 'bool check(std::__cxx11::string, std::__cxx11::string)':
savez.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s1.size(); i++)
                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 12 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 2432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 37 ms 560 KB Output is correct
2 Execution timed out 1078 ms 2560 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1064 ms 2784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 3440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1031 ms 4596 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1022 ms 6312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 27092 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1040 ms 44108 KB Time limit exceeded
2 Halted 0 ms 0 KB -