# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1029836 | earlyamazon | Savez (COCI15_savez) | C++14 | 63 ms | 40284 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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";
for (int poz = 0; poz <= s.size(); poz++){
if (indps < ps.size() && ps[indps] == poz) {
terwyn = max(terwyn, trie[ind].dp);
indps++;
}
if (poz == s.size()) break;
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++;
}
ind = trie[ind].s[s[poz] - 'A'];
}
trie[ind].dp = terwyn + 1;
wyn = max(wyn, trie[ind].dp);
}
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";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |