結果

問題 No.962 LCPs
ユーザー polylogKpolylogK
提出日時 2019-12-22 11:53:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,382 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 113,504 KB
実行使用メモリ 18,088 KB
最終ジャッジ日時 2023-10-12 02:27:13
合計ジャッジ時間 5,237 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,796 KB
testcase_01 AC 4 ms
7,724 KB
testcase_02 AC 5 ms
7,664 KB
testcase_03 AC 5 ms
7,788 KB
testcase_04 AC 4 ms
7,732 KB
testcase_05 AC 4 ms
7,740 KB
testcase_06 AC 3 ms
7,732 KB
testcase_07 AC 5 ms
7,736 KB
testcase_08 AC 4 ms
7,728 KB
testcase_09 AC 4 ms
7,728 KB
testcase_10 AC 5 ms
7,728 KB
testcase_11 AC 5 ms
7,872 KB
testcase_12 AC 4 ms
7,776 KB
testcase_13 AC 5 ms
7,716 KB
testcase_14 AC 5 ms
7,744 KB
testcase_15 AC 4 ms
7,780 KB
testcase_16 AC 5 ms
7,736 KB
testcase_17 AC 108 ms
18,088 KB
testcase_18 AC 53 ms
12,792 KB
testcase_19 AC 52 ms
12,748 KB
testcase_20 AC 36 ms
11,236 KB
testcase_21 AC 37 ms
11,160 KB
testcase_22 AC 28 ms
10,248 KB
testcase_23 AC 28 ms
10,236 KB
testcase_24 AC 23 ms
10,052 KB
testcase_25 AC 23 ms
9,752 KB
testcase_26 AC 19 ms
9,456 KB
testcase_27 AC 28 ms
10,752 KB
testcase_28 AC 17 ms
9,760 KB
testcase_29 AC 16 ms
9,456 KB
testcase_30 AC 25 ms
10,404 KB
testcase_31 AC 30 ms
11,192 KB
testcase_32 AC 15 ms
9,208 KB
testcase_33 AC 50 ms
12,492 KB
testcase_34 AC 20 ms
9,876 KB
testcase_35 AC 18 ms
9,480 KB
testcase_36 AC 21 ms
10,072 KB
testcase_37 AC 12 ms
8,796 KB
testcase_38 AC 12 ms
8,848 KB
testcase_39 AC 12 ms
8,792 KB
testcase_40 AC 13 ms
8,800 KB
testcase_41 AC 13 ms
8,844 KB
testcase_42 AC 13 ms
8,828 KB
testcase_43 AC 13 ms
8,832 KB
testcase_44 AC 13 ms
8,888 KB
testcase_45 AC 12 ms
8,856 KB
testcase_46 AC 13 ms
8,840 KB
testcase_47 AC 5 ms
8,084 KB
testcase_48 AC 4 ms
7,928 KB
testcase_49 AC 4 ms
8,192 KB
testcase_50 AC 6 ms
8,224 KB
testcase_51 AC 6 ms
8,180 KB
testcase_52 AC 5 ms
8,052 KB
testcase_53 AC 6 ms
7,988 KB
testcase_54 AC 5 ms
7,944 KB
testcase_55 AC 5 ms
7,996 KB
testcase_56 AC 5 ms
8,176 KB
testcase_57 AC 5 ms
7,664 KB
testcase_58 AC 6 ms
7,796 KB
testcase_59 AC 5 ms
7,712 KB
testcase_60 AC 6 ms
7,800 KB
testcase_61 AC 5 ms
7,732 KB
testcase_62 AC 6 ms
7,788 KB
testcase_63 AC 70 ms
14,404 KB
testcase_64 AC 6 ms
8,120 KB
testcase_65 AC 70 ms
14,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n;
  cin >> n;
  string t;
  cin >> t;
  const int S = 2e5;
  assert(1 <= t.size() && t.size() <= S);
  for(auto c : t) assert('a' <= c && c <= 'z');
  vector<vector<int>> cnt(S + 1);
  ll ans = t.size();
  assert(ans <= S);

  for(int i = 1; i < n; i++) {
    string s;
    cin >> s;
    for(auto c : s) assert('a' <= c && c <= 'z');
    assert(1 <= s.size() && s.size() <= S);
    int f = 0;
    while(f < s.size() && f < t.size() && s[f] == t[f]) f++;
    t = s;
    cnt.at(f).push_back(i);
    ans += s.size();
    assert(ans <= S);
  }
  //~ { char c; assert(!(cin >> c)); }
  set<int> st;
  st.insert(0);
  st.insert(n);
  for(int i = 0; i <= S; i++) {
    for(int j : cnt[i]) {
      auto nxt = st.lower_bound(j);
      auto prv = prev(nxt);
      ll x = *nxt - j;
      ll y = j - *prv;
      ans += ((x * x * y + x * y * y) / 2 + x * y) * i;
      st.insert(j);
    }
  }
  cout << ans << endl;
  return 0;
}
0