結果

問題 No.962 LCPs
ユーザー LeonardoneLeonardone
提出日時 2019-12-25 19:48:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,565 bytes
コンパイル時間 2,993 ms
コンパイル使用メモリ 73,492 KB
実行使用メモリ 10,000 KB
最終ジャッジ日時 2023-10-26 01:59:56
合計ジャッジ時間 4,033 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
9,292 KB
testcase_01 AC 5 ms
9,292 KB
testcase_02 AC 5 ms
9,292 KB
testcase_03 AC 5 ms
9,292 KB
testcase_04 AC 6 ms
9,292 KB
testcase_05 AC 6 ms
9,292 KB
testcase_06 AC 6 ms
9,292 KB
testcase_07 AC 5 ms
9,292 KB
testcase_08 AC 5 ms
9,292 KB
testcase_09 AC 5 ms
9,292 KB
testcase_10 AC 5 ms
9,292 KB
testcase_11 AC 5 ms
9,292 KB
testcase_12 AC 5 ms
9,292 KB
testcase_13 AC 5 ms
9,292 KB
testcase_14 AC 5 ms
9,292 KB
testcase_15 AC 5 ms
9,292 KB
testcase_16 AC 5 ms
9,292 KB
testcase_17 AC 27 ms
9,292 KB
testcase_18 AC 19 ms
9,292 KB
testcase_19 AC 18 ms
9,292 KB
testcase_20 AC 16 ms
9,292 KB
testcase_21 AC 15 ms
9,292 KB
testcase_22 AC 15 ms
9,292 KB
testcase_23 AC 14 ms
9,292 KB
testcase_24 AC 14 ms
9,292 KB
testcase_25 AC 14 ms
9,292 KB
testcase_26 AC 14 ms
9,292 KB
testcase_27 AC 15 ms
9,292 KB
testcase_28 AC 14 ms
9,292 KB
testcase_29 AC 13 ms
9,292 KB
testcase_30 AC 14 ms
9,292 KB
testcase_31 AC 16 ms
9,292 KB
testcase_32 AC 13 ms
9,292 KB
testcase_33 AC 18 ms
9,292 KB
testcase_34 AC 13 ms
9,292 KB
testcase_35 AC 14 ms
9,292 KB
testcase_36 AC 14 ms
9,292 KB
testcase_37 AC 13 ms
9,736 KB
testcase_38 AC 12 ms
9,736 KB
testcase_39 AC 13 ms
9,736 KB
testcase_40 AC 13 ms
9,736 KB
testcase_41 AC 12 ms
9,736 KB
testcase_42 AC 12 ms
9,736 KB
testcase_43 AC 12 ms
9,736 KB
testcase_44 AC 12 ms
9,736 KB
testcase_45 AC 13 ms
9,736 KB
testcase_46 AC 12 ms
9,736 KB
testcase_47 AC 8 ms
9,876 KB
testcase_48 AC 7 ms
9,840 KB
testcase_49 AC 9 ms
9,788 KB
testcase_50 AC 9 ms
9,804 KB
testcase_51 AC 9 ms
10,000 KB
testcase_52 AC 7 ms
9,800 KB
testcase_53 AC 9 ms
9,876 KB
testcase_54 AC 8 ms
9,800 KB
testcase_55 AC 8 ms
9,784 KB
testcase_56 AC 10 ms
10,000 KB
testcase_57 AC 9 ms
9,736 KB
testcase_58 AC 9 ms
9,736 KB
testcase_59 AC 9 ms
9,736 KB
testcase_60 AC 10 ms
9,736 KB
testcase_61 AC 10 ms
9,736 KB
testcase_62 AC 11 ms
9,736 KB
testcase_63 AC 19 ms
9,292 KB
testcase_64 AC 9 ms
10,000 KB
testcase_65 AC 20 ms
9,292 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 && 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