답안 #632395

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632395 2022-08-19T22:34:05 Z Neos Savez (COCI15_savez) C++14
0 / 120
38 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using ii = pair<ll, ll>;

#define fastIO ios::sync_with_stdio(0); cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define numBit(x) (__builtin_popcountll(1ll * (x)))
#define getBit(x, i) ((x) >> (i) & 1)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define MASK(x) 1ll << (x)

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x > y + eps) {
            x = y;
            return true;
        } else return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        X eps = 1e-9;
        if (x + eps < y) {
            x = y;
            return true;
        } else return false;
    }

const int N = 2e6 + 7;

int n;
ll val[N];
string s[N];
map<ll, int> mp;

struct Hash {
	const int base[2] = {311, 10007}, MOD = 1e9 + 7;
    string s;
    ll n;
    vector<vector<ll>> hsh, hsh2, pw;

    void init(string x) {
        s = x; n = sz(s); s = ' ' + s;

        hsh.resize(n + 3, vector<ll>(2, 0));
        hsh2.resize(n + 3, vector<ll>(2, 0));
        pw.resize(n + 3, vector<ll>(2, 1));
        for(int i = 1; i <= n; i++) {
            for (int j = 0; j < 2; j++) {
                pw[i][j] = pw[i - 1][j] * base[j] % MOD;
                hsh[i][j] = (hsh[i - 1][j] * base[j] + s[i]) % MOD;
            }
        }
        for (int i = n; i >= 1; i--)
            for (int j = 0; j < 2; j++)
                hsh2[i][j] = (hsh2[i + 1][j] * base[j] + s[i]) % MOD;
    }

    ll get(int l, int r) {
        ll v1 = (hsh[r][0] - hsh[l - 1][0] * pw[r - l + 1][0] % MOD + MOD) % MOD;
        ll v2 = (hsh[r][1] - hsh[l - 1][1] * pw[r - l + 1][1] % MOD + MOD) % MOD;
        return (v1 << 31) | v2;
    }

    ll getRev(int l, int r) {
        ll v1 = (hsh2[l][0] - hsh2[r + 1][0] * pw[r - l + 1][0] % MOD + MOD) % MOD;
        ll v2 = (hsh2[l][1] - hsh2[r + 1][1] * pw[r - l + 1][1] % MOD + MOD) % MOD;
        return (v1 << 31) | v2;
    }
} H[N];

signed main() {
    fastIO;
    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];  H[i].init(s[i]);
        val[i] = H[i].get(1, sz(s[i]));
    }

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        ll tmp = 0;
        for (int j = 1; j <= sz(s[i]); j++) {
            ll pre = H[i].get(1, j);
            ll suf = H[i].get(sz(s[i]) - j + 1, sz(s[i]));
            if (pre == suf) maximize(tmp, mp[pre] + 1);
        }
        maximize(ans, tmp); mp[val[i]] = tmp;
    }
    cout << ans;
}

Compilation message

savez.cpp: In function 'int main()':
savez.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
savez.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 28 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 38 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 36 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -