Submission #1029818

#TimeUsernameProblemLanguageResultExecution timeMemory
1029818earlyamazonSavez (COCI15_savez)C++14
0 / 120
57 ms65536 KiB
// wzorcowka KMP i trie #include <bits/stdc++.h> using namespace std; const int mn = 2e6+7; int n, terwyn, wyn, wsk = 2; vector<int> ps; struct node{ vector<int> s; int dp = 0; node(){ s.resize(26); } }; node trie[mn]; void zejdz(string s, int ind=1, int poz=0, int indps=0){ // cout<<"a: "<<s<<" "<<indps<<" "<<poz<<" "<<ind<<"\n"; if (indps < ps.size() && ps[indps] == poz) { terwyn = max(terwyn, trie[ind].dp); indps++; } if (poz == s.size()){ trie[ind].dp = terwyn + 1; wyn = max(wyn, trie[ind].dp); return; } if (!trie[ind].s[s[poz]-'A']) trie[ind].s[s[poz]-'A'] = wsk++; zejdz(s, trie[ind].s[s[poz] - 'A'], poz+1, indps); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; string s; for (int i = 0; i < n; i++){ cin>>s; vector<int> pi = {0}; ps.clear(); ps.push_back(s.size()); terwyn = 0; for (int j = 1; j < s.size(); j++){ int k = pi.back(); while (s[j] != s[k] && k){ k = pi[k-1]; } pi.push_back(k); if (s[j] == s[k]) { pi.back()++; } } // for (auto j : pi) cout<<j<<" "; // cout<<"\n"; int k = pi.back(); while (k){ ps.push_back(k); k = pi[k-1]; } reverse(ps.begin(), ps.end()); // for (auto j : ps) cout<<j<<" "; // cout<<"\n"; zejdz(s); } cout<<wyn<<"\n"; }

Compilation message (stderr)

savez.cpp: In function 'void zejdz(std::string, int, int, int)':
savez.cpp:22:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     if (indps < ps.size() && ps[indps] == poz) {
      |         ~~~~~~^~~~~~~~~~~
savez.cpp:26:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     if (poz == s.size()){
      |         ~~~~^~~~~~~~~~~
savez.cpp: In function 'int main()':
savez.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         for (int j = 1; j < s.size(); j++){
      |                         ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...