結果

問題 No.962 LCPs
ユーザー LeonardoneLeonardone
提出日時 2019-12-25 09:15:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,388 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 81,192 KB
実行使用メモリ 10,040 KB
最終ジャッジ日時 2023-10-24 19:39:58
合計ジャッジ時間 3,871 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,228 KB
testcase_01 AC 5 ms
9,228 KB
testcase_02 AC 5 ms
9,228 KB
testcase_03 AC 5 ms
9,228 KB
testcase_04 AC 5 ms
9,228 KB
testcase_05 AC 4 ms
9,228 KB
testcase_06 AC 5 ms
9,228 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 5 ms
9,228 KB
testcase_11 WA -
testcase_12 AC 5 ms
9,228 KB
testcase_13 WA -
testcase_14 AC 5 ms
9,228 KB
testcase_15 AC 5 ms
9,228 KB
testcase_16 WA -
testcase_17 AC 55 ms
9,228 KB
testcase_18 AC 32 ms
9,228 KB
testcase_19 AC 31 ms
9,228 KB
testcase_20 AC 23 ms
9,228 KB
testcase_21 AC 22 ms
9,228 KB
testcase_22 AC 19 ms
9,228 KB
testcase_23 AC 19 ms
9,228 KB
testcase_24 AC 18 ms
9,228 KB
testcase_25 AC 18 ms
9,228 KB
testcase_26 AC 15 ms
9,228 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
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 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 AC 9 ms
9,776 KB
testcase_61 AC 9 ms
9,776 KB
testcase_62 AC 10 ms
9,776 KB
testcase_63 WA -
testcase_64 AC 9 ms
10,040 KB
testcase_65 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

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

int n;
vector<string> vs(2e5);
unsigned 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 hRow = 0;
        for (int b=25; b >=0; b--) {
            int v = hRow | (1 << b);
            if (minRow <= v && v <= maxRow) {
                if (vs[v].size() <= col) {
                    hRow = v;
                }
            }
        }
        if (minRow <= hRow && hRow < maxRow && vs[hRow].size() <= col) {
            unsigned long long len = hRow - minRow + 1;
            // cout << "[" << col << "] " << "nosize: " <<  hRow << ", (" << len << ")" << endl;
            unsigned long long lp = 1, rp = len;
            while (lp <= rp) {
                ans += lp * rp * (lp == rp ? 1ULL : 2ULL);
                lp++; rp--;
            }
        }
    }
    for (char ch = 'a'; ch <= 'z'; ch++) {
        int lRow = 0, hRow = 0;
        for (int b=25; b >=0; b--) {
            int u = lRow | (1 << b);
            int v = hRow | (1 << b);
            if (minRow <= u && u <= maxRow) {
                if (vs[u].size() <= col || vs[u][col] < ch) {
                    lRow = u;
                }
            }
            if (minRow <= v && v <= maxRow) {
                if (vs[v].size() <= col || vs[v][col] <= ch) {
                    hRow = v;
                }
            }
        }
        if (vs[hRow].size() <= col || vs[hRow][col] != ch) { continue; }
        if (vs[lRow].size() <= col || vs[lRow][col] != ch) { lRow++; }
        unsigned long long len = hRow - lRow + 1;
        // cout << "[" << col << "] " << ch << ": " << lRow << ", " << hRow << ", (" << len << ")" << endl;
        if (len == 1) {
            ans += (unsigned long long)vs[hRow].size() - (unsigned long long)col;
        } else {
            unsigned long long lp = 1, rp = len;
            while (lp <= rp) {
                ans += lp * rp * (lp == rp ? 1ULL : 2ULL);
                lp++; rp--;
            }
            bins(col + 1, lRow, hRow);
        }
    }
}
0