結果

問題 No.962 LCPs
ユーザー LeonardoneLeonardone
提出日時 2019-12-25 19:45:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,619 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 73,488 KB
実行使用メモリ 10,044 KB
最終ジャッジ日時 2023-10-26 01:55:12
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,336 KB
testcase_01 AC 5 ms
9,336 KB
testcase_02 AC 5 ms
9,336 KB
testcase_03 AC 5 ms
9,336 KB
testcase_04 AC 5 ms
9,336 KB
testcase_05 AC 6 ms
9,336 KB
testcase_06 AC 5 ms
9,336 KB
testcase_07 AC 5 ms
9,336 KB
testcase_08 AC 6 ms
9,336 KB
testcase_09 AC 6 ms
9,336 KB
testcase_10 AC 6 ms
9,336 KB
testcase_11 AC 5 ms
9,336 KB
testcase_12 AC 5 ms
9,336 KB
testcase_13 AC 5 ms
9,336 KB
testcase_14 AC 5 ms
9,336 KB
testcase_15 AC 5 ms
9,336 KB
testcase_16 AC 5 ms
9,336 KB
testcase_17 AC 27 ms
9,336 KB
testcase_18 AC 18 ms
9,336 KB
testcase_19 AC 18 ms
9,336 KB
testcase_20 AC 15 ms
9,336 KB
testcase_21 AC 15 ms
9,336 KB
testcase_22 AC 14 ms
9,336 KB
testcase_23 AC 14 ms
9,336 KB
testcase_24 AC 14 ms
9,336 KB
testcase_25 AC 13 ms
9,336 KB
testcase_26 AC 13 ms
9,336 KB
testcase_27 AC 15 ms
9,336 KB
testcase_28 AC 13 ms
9,336 KB
testcase_29 AC 12 ms
9,336 KB
testcase_30 AC 14 ms
9,336 KB
testcase_31 AC 16 ms
9,336 KB
testcase_32 AC 12 ms
9,336 KB
testcase_33 AC 19 ms
9,336 KB
testcase_34 AC 14 ms
9,336 KB
testcase_35 AC 13 ms
9,336 KB
testcase_36 AC 14 ms
9,336 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 9 ms
9,920 KB
testcase_48 AC 8 ms
9,884 KB
testcase_49 AC 9 ms
9,832 KB
testcase_50 AC 9 ms
9,848 KB
testcase_51 AC 9 ms
10,044 KB
testcase_52 AC 7 ms
9,844 KB
testcase_53 AC 9 ms
9,920 KB
testcase_54 AC 8 ms
9,844 KB
testcase_55 AC 7 ms
9,828 KB
testcase_56 AC 9 ms
10,044 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 10 ms
9,780 KB
testcase_61 AC 10 ms
9,780 KB
testcase_62 AC 10 ms
9,780 KB
testcase_63 AC 20 ms
9,336 KB
testcase_64 AC 10 ms
10,044 KB
testcase_65 AC 20 ms
9,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void bins(int col, int minRow, int maxRow);

int n;
vector<string> vs(2e5);
long long ans;

int main() {
    cin >> n;
    vs.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> vs[i];
    }
    // sort(vs.begin(), vs.end());
    
    // for (int i = 0; i < n; i++) cout << vs[i] << endl;
    
    bins(0, 0, n-1);
    
    cout << ans << endl;
    return 0;
}

void bins(int col, int minRow, int maxRow) {
    int lRow = minRow;
    for (int row = minRow; row <= maxRow; row++) {
        if (vs[lRow].size() <= col) {
            lRow = row; continue;
        }
        if (vs[row].size() <= col) {
            lRow = row; continue;
        } else if (vs[row][col] == vs[lRow][col]) {
            continue;
        }
        int len = row - lRow;
        if (len == 1) {
            ans += (long long)vs[lRow].size() - (long long)col;
        } else {
            long long lp = 1, rp = len;
            while (lp <= rp) {
                ans += lp * rp * (lp == rp ? 1LL : 2LL);
                lp++; rp--;
            }
            bins(col + 1, lRow, row - 1);
        }
        lRow = row;
    }
    if (vs[lRow].size() >= col) {
        int row = maxRow + 1;
        int len = row - lRow;
        if (len == 1) {
            ans += (long long)vs[lRow].size() - (long long)col;
        } else {
            long long lp = 1, rp = len;
            while (lp <= rp) {
                ans += lp * rp * (lp == rp ? 1LL : 2LL);
                lp++; rp--;
            }
            bins(col + 1, lRow, row - 1);
        }
    }
}
0