Submission #1028101

# Submission time Handle Problem Language Result Execution time Memory
1028101 2024-07-19T13:38:07 Z earlyamazon Savez (COCI15_savez) C++14
120 / 120
64 ms 17916 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mn = 2e6+7;
const int mod1 = 1e9+7;
const int mod2 = 1e9+9;
const int p1 = 269;
const int p2 = 271;
int32_t n,wyn;
map<int32_t, int32_t> dp;
int pot[mn];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie();
    cin>>n;
    pot[0] = 1;
    for (int i = 1; i < mn; i++){
        pot[i] = pot[i-1]*p1%mod1;
    }
    string s;
    vector<int> hpref;
    for (int i = 0; i < n; i++){
        hpref.clear();
        cin>>s;
        hpref.resize(s.size()+1);
        hpref[0] = 0;
        for (int j = 1; j <= (int)s.size(); j++){
            hpref[j] = (hpref[j-1]*p1+s[j-1])%mod1;
        }
        int32_t mx = 0;
        for (int j = 1; j <= (int)s.size(); j++){
            int h = hpref[j];
            if (dp.count(h)){
                if (h == (hpref[s.size()]-((hpref[s.size()-j]*pot[j])%mod1)+mod1)%mod1){
                    mx = max(mx, dp[h]);
                }
            }
        }
        mx++;
        wyn = max(wyn, mx);
        dp[hpref.back()] = mx;
        // cout<<hpref[i].size()<<" "<<hpref[i].back().first<<" "<<hpref[i].back().second<<" "<<mx<<"\n";
    }
    cout<<wyn<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 15968 KB Output is correct
2 Correct 15 ms 16040 KB Output is correct
3 Correct 15 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 15964 KB Output is correct
2 Correct 15 ms 15964 KB Output is correct
3 Correct 18 ms 16100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 16988 KB Output is correct
2 Correct 24 ms 17104 KB Output is correct
3 Correct 39 ms 16936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 15960 KB Output is correct
2 Correct 33 ms 16980 KB Output is correct
3 Correct 37 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 16984 KB Output is correct
2 Correct 28 ms 16976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 17004 KB Output is correct
2 Correct 30 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 16988 KB Output is correct
2 Correct 35 ms 16972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 16980 KB Output is correct
2 Correct 29 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 17240 KB Output is correct
2 Correct 31 ms 17248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 17228 KB Output is correct
2 Correct 40 ms 17228 KB Output is correct
3 Correct 64 ms 17916 KB Output is correct