結果

問題 No.515 典型LCP
ユーザー tossytossy
提出日時 2017-05-07 12:32:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 718 ms / 1,000 ms
コード長 1,584 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 169,940 KB
実行使用メモリ 24,228 KB
最終ジャッジ日時 2023-10-12 16:00:32
合計ジャッジ時間 7,380 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 445 ms
24,208 KB
testcase_01 AC 687 ms
24,228 KB
testcase_02 AC 718 ms
20,668 KB
testcase_03 AC 4 ms
8,068 KB
testcase_04 AC 4 ms
8,088 KB
testcase_05 AC 190 ms
20,652 KB
testcase_06 AC 194 ms
20,580 KB
testcase_07 AC 190 ms
20,676 KB
testcase_08 AC 192 ms
20,592 KB
testcase_09 AC 392 ms
20,456 KB
testcase_10 AC 179 ms
20,672 KB
testcase_11 AC 180 ms
20,644 KB
testcase_12 AC 177 ms
20,652 KB
testcase_13 AC 331 ms
20,456 KB
testcase_14 AC 22 ms
20,820 KB
testcase_15 AC 208 ms
20,556 KB
testcase_16 AC 209 ms
20,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 1000000009L
#define DOM 1000000021L
#define MMM 1000000033L

vector<long> hash1[100005], hash2[100005];
int sz[100005];
char s[800005];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long n;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    sz[i] = s.size();
    hash1[i].resize(sz[i]+1);
    hash2[i].resize(sz[i]+1);
    hash1[i][0] = 0;
    hash2[i][0] = 0;
    rep(j,sz[i]){
      hash1[i][j+1] = hash1[i][j]*MOD + s[j];
      hash1[i][j+1] %= DOM;
      hash2[i][j+1] = hash2[i][j]*MOD + s[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(sz[i], sz[j])+1;
    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;
}
0