Submission #305328

#TimeUsernameProblemLanguageResultExecution timeMemory
305328FlashGamezzzRima (COCI17_rima)C++17
28 / 140
618 ms89936 KiB
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <queue> using namespace std; int lets[1000000][26] = {}, inds[1000000] = {}, par[1000000], dp[500000] = {}, winds[500000], sz = 1, ind, ans = 0; vector<string> strs; string s; void add(int c, int i){ if (i == s.length()){ inds[c] = ind+1; winds[ind] = c; return; } int l = int(s[s.length()-i-1])-97; if (lets[c][l] == 0){ lets[c][l] = sz; par[sz] = c, sz++; } add(lets[c][l], i+1); } bool comp(string a, string b){ if (a.length() == b.length()){ return a < b; } return a.length() < b.length(); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; for (int i = 0; i < n; i++){ string s; cin >> s; strs.push_back(s); } sort(strs.begin(), strs.end(), comp); for (int i = 0; i < n; i++){ s = strs[i]; ind = i; add(0, 0); } dp[0] = 1; for (int i = 1; i < n; i++){ int pi = par[winds[i]], fr = -1; dp[i] = 1; if (inds[pi] > 0){ fr = inds[pi]-1; } for (int j = 0; lets[pi][j] != winds[i]; j++){ if (inds[lets[pi][j]] > 0){ fr = inds[lets[pi][j]]-1; } } if (fr > -1){ dp[i] += dp[fr]; } ans = max(ans, dp[i]); } cout << ans << endl; }

Compilation message (stderr)

rima.cpp: In function 'void add(int, int)':
rima.cpp:19:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  if (i == s.length()){
      |      ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...