# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1029832 | 2024-07-21T11:45:41 Z | earlyamazon | Savez (COCI15_savez) | C++14 | 1000 ms | 46108 KB |
// wzorcowka KMP i trie #include <bits/stdc++.h> using namespace std; const int mn = 1e6+7; int n, terwyn, wyn, wsk = 2; vector<int> ps; struct node{ vector<int> s; int dp = 0; }; 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.size() < 26) trie[ind].s.resize(26); 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; trie[1].s.resize(26); 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 31768 KB | Output is correct |
2 | Correct | 15 ms | 31576 KB | Output is correct |
3 | Correct | 13 ms | 31732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 31576 KB | Output is correct |
2 | Correct | 12 ms | 31576 KB | Output is correct |
3 | Correct | 24 ms | 41564 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 123 ms | 36944 KB | Output is correct |
2 | Correct | 121 ms | 37712 KB | Output is correct |
3 | Execution timed out | 1045 ms | 40232 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 36696 KB | Output is correct |
2 | Execution timed out | 1065 ms | 46108 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 37356 KB | Output is correct |
2 | Correct | 81 ms | 37204 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 37232 KB | Output is correct |
2 | Correct | 50 ms | 37136 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 37200 KB | Output is correct |
2 | Correct | 49 ms | 37120 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 37204 KB | Output is correct |
2 | Correct | 43 ms | 37976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 32340 KB | Output is correct |
2 | Correct | 41 ms | 32344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 32900 KB | Output is correct |
2 | Correct | 51 ms | 33364 KB | Output is correct |
3 | Correct | 61 ms | 33620 KB | Output is correct |