結果
問題 | No.515 典型LCP |
ユーザー |
![]() |
提出日時 | 2017-05-06 02:21:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 976 ms / 1,000 ms |
コード長 | 1,201 bytes |
コンパイル時間 | 1,857 ms |
コンパイル使用メモリ | 172,408 KB |
実行使用メモリ | 24,472 KB |
最終ジャッジ日時 | 2024-09-14 10:22:37 |
合計ジャッジ時間 | 9,765 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct RollingHash { int n; static const unsigned P = 1000000007U; vector<unsigned long long> pow, phash; RollingHash() {}; template<typename T> RollingHash(const T& s, unsigned long long Q = 1) { n = s.size(); pow.resize(n + 1); phash.resize(n + 1); pow[0] = Q; phash[0] = 0; for(int i = 0; i < n; i++) { pow[i + 1] = pow[i] * P; phash[i + 1] = s[i] + phash[i] * P; } } unsigned long long get(int i) const { return phash[i]; } unsigned long long get(int i, int j) const { return get(j) - get(i) * pow[j - i]; } }; RollingHash h[100000]; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, M, x, d; cin >> N; for(int i = 0; i < N; i++) { string s; cin >> s; h[i] = RollingHash(s); } cin >> M >> x >> d; ll ans = 0; for(int k = 0; k < M; k++) { int i = x / (N - 1) + 1, j = x % (N - 1) + 1; if(i > j) swap(i, j); else j++; x = (x + d) % (N * (N - 1)); i--, j--; int ok = 0, ng = min(h[i].n, h[j].n) + 1; while(abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if(h[i].get(mid) == h[j].get(mid)) ok = mid; else ng = mid; } ans += ok; } cout << ans << endl; }