Submission #994104

#TimeUsernameProblemLanguageResultExecution timeMemory
994104vjudge1Rima (COCI17_rima)C++17
56 / 140
238 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 10; int n, sz; string S[N]; int dp[N * 20]; bool have[N * 20]; vector<pair<char, int>> g[N * 20]; void add(string s){ int cur = 0; for (int i = 0; i < s.size(); i ++){ int nxt = 0; for (auto [c, v] : g[cur]){ if (c == s[i]){ nxt = v; break; } } if (nxt){ cur = nxt; } else{ for (int j = i; j < s.size(); j ++){ sz++; g[cur].push_back({s[j], sz}); cur = sz; } break; } } have[cur] = 1; } void print(){ for (int i = 0; i <= sz; i ++){ cout << "current node = " << i << endl; for (auto [c, v] : g[i]){ cout << "child " << v << " with char " << c << endl; } } } int main(){ cin >> n; for (int i = 0; i < n; i ++){ cin >> S[i]; reverse(S[i].begin(), S[i].end()); add(S[i]); } int ans = 0; // print(); // cout << endl; for (int i = sz; i >= 0; i --){ // cout << "current node = " << i << endl; int sm = 0; int mx = 0; for (auto [c, v] : g[i]){ // cout << "going to " << v << " with char " << c << endl; if (have[v]){ sm ++; mx = max(mx, dp[v]); } } if (sm == 0) dp[i] = 0; else dp[i] = sm + mx; ans = max(ans, dp[i]); // cout << "Answer = " << dp[i] << endl; } cout << ans << endl; }

Compilation message (stderr)

rima.cpp: In function 'void add(std::string)':
rima.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < s.size(); i ++){
      |                     ~~^~~~~~~~~~
rima.cpp:26:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             for (int j = i; j < s.size(); j ++){
      |                             ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...