Submission #1028069

# Submission time Handle Problem Language Result Execution time Memory
1028069 2024-07-19T13:02:08 Z earlyamazon Savez (COCI15_savez) C++14
24 / 120
37 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int mn = 1e6+7;
const int mod1 = 1e9+7;
const int mod2 = 1e9+9;
const int p1 = 269;
const int p2 = 271;
int32_t n,wyn;
string t[mn];
vector<int> hpref[mn];
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;
    }
    for (int i = 0; i < n; i++){
        cin>>t[i];
        hpref[i].push_back(0);
        for (int j = 1; j <= (int)t[i].size(); j++){
            hpref[i].push_back((hpref[i].back()*p1+t[i][j-1])%mod1);
        }
        int32_t mx = 0;
        for (int j = 1; j <= (int)t[i].size(); j++){
            int h = hpref[i][j];
            if (h == (hpref[i][t[i].size()]-((hpref[i][t[i].size()-j]*pot[j])%mod1)+mod1)%mod1){
                mx = max(mx, dp[h]);
            }
        }
        mx++;
        wyn = max(wyn, mx);
        dp[hpref[i].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 24 ms 63068 KB Output is correct
2 Correct 24 ms 63060 KB Output is correct
3 Correct 24 ms 63068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 63056 KB Output is correct
2 Correct 24 ms 63068 KB Output is correct
3 Correct 25 ms 63708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 37 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 63832 KB Output is correct
2 Runtime error 30 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -