結果

問題 No.515 典型LCP
ユーザー koba-e964koba-e964
提出日時 2016-11-06 02:26:30
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,293 bytes
コンパイル時間 469 ms
コンパイル使用メモリ 64,448 KB
実行使用メモリ 7,508 KB
最終ジャッジ日時 2023-09-22 20:29:22
合計ジャッジ時間 8,498 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
6,656 KB
testcase_01 AC 152 ms
6,484 KB
testcase_02 TLE -
testcase_03 AC 5 ms
6,464 KB
testcase_04 AC 4 ms
6,524 KB
testcase_05 AC 79 ms
7,508 KB
testcase_06 AC 80 ms
7,368 KB
testcase_07 AC 80 ms
7,440 KB
testcase_08 AC 87 ms
7,368 KB
testcase_09 TLE -
testcase_10 AC 408 ms
7,180 KB
testcase_11 AC 514 ms
7,212 KB
testcase_12 AC 516 ms
7,172 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int N = 100010;
string s[N];


// Greedy exhaustive search. It should fail with TLE.
int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  assert (n <= 100000);
  int tot_len = 0;
  REP(i, 0, n) {
    cin >> s[i];
    tot_len += s[i].length();
  }
  assert (tot_len <= 800000);
  int m;
  cin >> m;
  assert (m <= 3000000);
  ll x, d;
  cin >> x >> d;
  ll lim = ll(n) * ll(n - 1);
  assert (0 <= x);
  assert (x < lim);
  assert (d < lim);
  assert (0 <= d);
  ll total = 0;
  REP(loop_cnt, 0, m) {
    int i, j;
    i = (x / (n - 1)) + 1;
    j = (x % (n - 1)) + 1;
    if (i > j) {
      swap(i, j);
    } else {
      j++;
    }
    assert (1 <= i);
    assert (i < j);
    assert (j <= n);
    i--, j--;
    int pos = 0;
    int lim = min(s[i].length(), s[j].length());
    for (; pos < lim; ++pos) {
      if (s[i][pos] != s[j][pos]) break;
    }
    total += pos;
    x = (x + d) % (ll(n) * ll(n - 1));
  }
  cout << total << "\n";
}
0