結果

問題 No.962 LCPs
ユーザー lumc_lumc_
提出日時 2019-12-22 18:00:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,712 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 107,476 KB
実行使用メモリ 6,260 KB
最終ジャッジ日時 2023-10-12 14:34:16
合計ジャッジ時間 10,962 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,412 KB
testcase_01 AC 3 ms
5,604 KB
testcase_02 AC 3 ms
5,388 KB
testcase_03 AC 4 ms
5,360 KB
testcase_04 AC 4 ms
5,412 KB
testcase_05 AC 3 ms
5,328 KB
testcase_06 AC 4 ms
5,412 KB
testcase_07 AC 3 ms
5,408 KB
testcase_08 AC 3 ms
5,356 KB
testcase_09 AC 4 ms
5,452 KB
testcase_10 AC 4 ms
5,364 KB
testcase_11 AC 3 ms
5,364 KB
testcase_12 AC 3 ms
5,416 KB
testcase_13 AC 3 ms
5,412 KB
testcase_14 AC 4 ms
5,460 KB
testcase_15 AC 3 ms
5,488 KB
testcase_16 AC 4 ms
5,464 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
権限があれば一括ダウンロードができます

ソースコード

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 = 1e5;
  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