結果
問題 |
No.515 典型LCP
|
ユーザー |
![]() |
提出日時 | 2017-05-07 11:53:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,648 bytes |
コンパイル時間 | 1,830 ms |
コンパイル使用メモリ | 173,588 KB |
実行使用メモリ | 26,496 KB |
最終ジャッジ日時 | 2024-09-14 14:38:23 |
合計ジャッジ時間 | 8,691 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 7 TLE * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define mp(a,b) make_pair((a),(b)) #define pb(a) push_back((a)) #define all(x) (x).begin(),(x).end() #define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x)) #define fi first #define se second #define dbg(x) cout<<#x" = "<<((x))<<endl template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;} template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;} #define INF 2147483600 #define MOD 1000000007L #define DOM 1000000009L #define MMM 1000000033L int main(){ cin.tie(0); ios::sync_with_stdio(false); long n; cin>>n; vector<string> vec(n); rep(i,n) cin>>vec[i]; vector<vector<long>> hash1(n), hash2(n); rep(i,n){ hash1[i].resize(vec[i].size()+1); hash1[i][0] = 0; rep(j,vec[i].size()){ hash1[i][j+1] = hash1[i][j]*MOD + vec[i][j]; hash1[i][j+1] %= MMM; } } rep(i,n){ hash2[i].resize(vec[i].size()+1); hash2[i][0] = 0; rep(j,vec[i].size()){ hash2[i][j+1] = hash2[i][j]*DOM + vec[i][j]; hash2[i][j+1] %= MMM; } } long m,x,d; cin>>m>>x>>d; long ans = 0; rep(_,m){ long i = (x/(n-1)); long j = (x%(n-1)); if(i<=j) j++; int l=0, r=min(vec[i].size(), vec[j].size()); while(r-l>1){ int mid = (r+l)/2; if(hash1[i][mid]==hash1[j][mid] && hash2[i][mid]==hash2[j][mid]) l=mid; else r=mid; } ans += l; x = (x+d)%(n*(n-1)); } cout << ans << endl; return 0; }