답안 #564106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564106 2022-05-18T15:02:02 Z perchuts Savez (COCI15_savez) C++17
108 / 120
141 ms 65536 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<vector<ll>>hsh, revHsh;
vector<string>v;


void computeHash(int idx){
    int n = qnt[idx];
    vector<vector<ll>>ret[2];
    hsh[idx].pb(ll(v[idx][0]-'A'+1ll));
    for(int i=1;i<n;++i){
        ll add = hsh[idx].back()*base+ll(v[idx][i]-'A'+1ll);
        hsh[idx].pb(add);
        hsh[idx].back() %= mod;
    }
    revHsh[idx].pb(ll(v[idx][n-1]-'A'+1ll));
    ll act = 1ll;
    for(int i=n-2;i>=0;--i){
        act = (act*base)%mod;
        ll add = revHsh[idx].back()+act*ll(v[idx][i]-'A'+1ll);
        revHsh[idx].pb(add);
        revHsh[idx].back() %= 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]);
    }

    hsh.resize(n), revHsh.resize(n);
    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[idx][j]==revHsh[idx][j])ckmax(res,dp[int(hsh[idx][j])]); 
        ++res;
        if(hsh[idx][m-1]==revHsh[idx][m-1])ckmax(dp[int(hsh[idx][m-1])], res); 
        ckmax(best, res);
    }

    cout<<best<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 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 3 ms 1748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 17340 KB Output is correct
2 Correct 41 ms 17392 KB Output is correct
3 Correct 42 ms 19868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1876 KB Output is correct
2 Correct 30 ms 19680 KB Output is correct
3 Correct 39 ms 20408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 24600 KB Output is correct
2 Correct 39 ms 24956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 25816 KB Output is correct
2 Correct 43 ms 25876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 28196 KB Output is correct
2 Correct 53 ms 28092 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 31828 KB Output is correct
2 Correct 66 ms 31884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 50100 KB Output is correct
2 Correct 105 ms 51192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 64492 KB Output is correct
2 Correct 130 ms 65536 KB Output is correct
3 Runtime error 92 ms 65536 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -