답안 #564109

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564109 2022-05-18T15:06:59 Z perchuts Savez (COCI15_savez) C++17
120 / 120
100 ms 37516 KB
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;

const int inf = 2e9+1;
const ll mod = 1e9+7;
const ll base = 101;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }

vector<int>qnt;
vector<string>v;

ll hsh[2000001], revHsh[2000001];

void computeHash(int idx){
    int n = qnt[idx];
    hsh[0] = ll(v[idx][0]-'A'+1ll);
    for(int i=1;i<n;++i){
        hsh[i] = hsh[i-1]*base+ll(v[idx][i]-'A'+1ll);
        hsh[i] %= mod;
    }
    revHsh[0] = ll(v[idx][n-1]-'A'+1ll);
    ll act = 1ll;
    for(int i=n-2;i>=0;--i){
        act = (act*base)%mod;
        revHsh[n-1-i] = revHsh[n-2-i]+act*ll(v[idx][i]-'A'+1ll);
        revHsh[n-1-i] %= mod;
    }
}

unordered_map<int,int>dp;

int main(){_
    int n;cin>>n;
    v.resize(n), qnt.resize(n);

    for(int i=0;i<n;++i){
        cin>>v[i];
        qnt[i] = sz(v[i]);
    }

    int best = 0;

    for(int i=0;i<n;++i){
        int idx = i;
        computeHash(idx);
        int m = qnt[idx], res = 0;
        for(int j=0;j<m;++j)if(hsh[j]==revHsh[j])ckmax(res,dp[int(hsh[j])]); 
        ++res;
        if(hsh[m-1]==revHsh[m-1])ckmax(dp[int(hsh[m-1])], res); 
        ckmax(best, res);
    }

    cout<<best<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 1492 KB Output is correct
2 Correct 32 ms 1492 KB Output is correct
3 Correct 33 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 19 ms 1484 KB Output is correct
3 Correct 24 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1748 KB Output is correct
2 Correct 23 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 2308 KB Output is correct
2 Correct 25 ms 2340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 3156 KB Output is correct
2 Correct 23 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3924 KB Output is correct
2 Correct 29 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 8804 KB Output is correct
2 Correct 33 ms 8804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 14428 KB Output is correct
2 Correct 53 ms 14680 KB Output is correct
3 Correct 100 ms 37516 KB Output is correct