結果

問題 No.515 典型LCP
ユーザー vjudge1
提出日時 2025-03-15 00:14:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 755 ms / 1,000 ms
コード長 1,203 bytes
コンパイル時間 1,975 ms
コンパイル使用メモリ 165,352 KB
実行使用メモリ 16,840 KB
最終ジャッジ日時 2025-03-15 00:14:08
合計ジャッジ時間 8,106 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N = 1e5 + 10;
ll n;
string s[N];
ll m, x, d;
vector<ll> h[N];
inline bool check(ll a, ll b, ll c)
{
    if (min(s[a].size(), s[b].size()) < c)
        return 0;
    return h[a][c] == h[b][c];
}
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> s[i];
        h[i].resize(s[i].size() + 1, 0);
        ll pw = 1;
        for (ll j = 1; j <= s[i].size(); j++)
            h[i][j] = h[i][j - 1] + pw * s[i][j - 1], pw *= 131;
    }
    cin >> m >> x >> d;
    ll ans = 0;
    for (ll i = 1; i <= m; i++)
    {
        ll a = (x / (n - 1)) + 1, b = (x % (n - 1)) + 1;
        if (a > b)
            swap(a, b);
        else
            b += 1;
        x = (x + d) % (n * (n - 1));
        ll l = 0, r = 1e6, res = l;
        while (r >= l)
        {
            ll mid = (l + r) >> 1;
            if (check(a, b, mid))
                res = mid, l = mid + 1;
            else
                r = mid - 1;
        }
        ans += res;
    }
    cout << ans << endl;
    return 0;
}
0