結果

問題 No.962 LCPs
ユーザー LeonardoneLeonardone
提出日時 2019-12-25 19:44:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,616 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 73,420 KB
実行使用メモリ 10,000 KB
最終ジャッジ日時 2023-10-26 01:53:39
合計ジャッジ時間 5,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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