結果

問題 No.962 LCPs
ユーザー lumc_lumc_
提出日時 2019-12-22 18:01:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 972 ms
コンパイル使用メモリ 107,876 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2023-10-12 14:34:26
合計ジャッジ時間 3,896 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,724 KB
testcase_01 AC 4 ms
7,736 KB
testcase_02 AC 5 ms
7,720 KB
testcase_03 AC 5 ms
7,720 KB
testcase_04 AC 4 ms
7,720 KB
testcase_05 AC 4 ms
7,648 KB
testcase_06 AC 5 ms
7,728 KB
testcase_07 AC 4 ms
7,656 KB
testcase_08 AC 5 ms
7,772 KB
testcase_09 AC 5 ms
7,660 KB
testcase_10 AC 5 ms
7,796 KB
testcase_11 AC 5 ms
7,800 KB
testcase_12 AC 4 ms
7,676 KB
testcase_13 AC 5 ms
7,796 KB
testcase_14 AC 4 ms
7,648 KB
testcase_15 AC 4 ms
7,652 KB
testcase_16 AC 5 ms
7,800 KB
testcase_17 AC 19 ms
9,344 KB
testcase_18 AC 13 ms
8,832 KB
testcase_19 AC 13 ms
8,508 KB
testcase_20 AC 10 ms
8,600 KB
testcase_21 AC 10 ms
8,504 KB
testcase_22 AC 9 ms
8,440 KB
testcase_23 AC 9 ms
8,240 KB
testcase_24 AC 9 ms
8,300 KB
testcase_25 AC 9 ms
8,148 KB
testcase_26 AC 8 ms
8,216 KB
testcase_27 AC 11 ms
8,288 KB
testcase_28 AC 8 ms
8,228 KB
testcase_29 AC 8 ms
8,160 KB
testcase_30 AC 9 ms
8,212 KB
testcase_31 AC 12 ms
8,552 KB
testcase_32 AC 8 ms
8,348 KB
testcase_33 AC 14 ms
8,516 KB
testcase_34 AC 9 ms
8,224 KB
testcase_35 AC 8 ms
8,388 KB
testcase_36 AC 9 ms
8,328 KB
testcase_37 AC 9 ms
8,328 KB
testcase_38 AC 8 ms
8,064 KB
testcase_39 AC 8 ms
8,068 KB
testcase_40 AC 9 ms
8,216 KB
testcase_41 AC 9 ms
8,136 KB
testcase_42 AC 9 ms
8,160 KB
testcase_43 AC 8 ms
8,144 KB
testcase_44 AC 9 ms
8,072 KB
testcase_45 AC 9 ms
8,108 KB
testcase_46 AC 9 ms
8,128 KB
testcase_47 AC 6 ms
8,064 KB
testcase_48 AC 5 ms
8,052 KB
testcase_49 AC 6 ms
8,132 KB
testcase_50 AC 5 ms
8,152 KB
testcase_51 AC 5 ms
8,160 KB
testcase_52 AC 4 ms
7,980 KB
testcase_53 AC 4 ms
7,912 KB
testcase_54 AC 5 ms
7,984 KB
testcase_55 AC 5 ms
7,960 KB
testcase_56 AC 5 ms
8,168 KB
testcase_57 AC 5 ms
7,792 KB
testcase_58 AC 5 ms
7,656 KB
testcase_59 AC 6 ms
7,736 KB
testcase_60 AC 6 ms
7,908 KB
testcase_61 AC 4 ms
7,736 KB
testcase_62 AC 5 ms
7,720 KB
testcase_63 AC 15 ms
8,800 KB
testcase_64 AC 5 ms
8,096 KB
testcase_65 AC 15 ms
8,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// O(S^1.5)
// 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);
  }
  vector<int> used(n+1);
  used[0] = used[n] = 1;
  for(int i = 0; i <= S; i++) if(cnt[i].size()) {
    int now = 0;
    int last = 0, last2;
    int lasti = -1;
    ll x, x2;
    for(int k = 1; k <= n; k++) {
      if(now < cnt[i].size() && cnt[i].at(now) == k) {
        used[k] = 1;
        x2 = k - last;
        last2 = last;
      }
      if(lasti >= 0 && used[k]) {
        ll y = k - lasti;
        ans += ((x * x * y + x * y * y) / 2 + x * y) * i;
        lasti = -1;
      }
      if(used[k]) last = k;
      if(now < cnt[i].size() && cnt[i].at(now) == k) {
        now++;
        x = x2;
        last = last2;
        lasti = k;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
0