結果

問題 No.515 典型LCP
ユーザー koba-e964koba-e964
提出日時 2016-11-06 00:01:45
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 883 bytes
コンパイル時間 1,287 ms
コンパイル使用メモリ 63,644 KB
実行使用メモリ 8,180 KB
最終ジャッジ日時 2023-09-22 20:28:32
合計ジャッジ時間 5,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
権限があれば一括ダウンロードができます

ソースコード

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];

int main(void){
  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 <= 400000);
  int m;
  cin >> m;
  assert (m <= 100000);
  REP(loop_cnt, 0, m) {
    int i, j;
    cin >> i >> 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;
    }
    cout << pos << endl;
  }
}
0