結果

問題 No.515 典型LCP
ユーザー mamekinmamekin
提出日時 2017-05-05 23:23:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,807 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 116,948 KB
実行使用メモリ 32,340 KB
最終ジャッジ日時 2023-10-12 11:07:39
合計ジャッジ時間 13,247 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 857 ms
27,588 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 362 ms
27,940 KB
testcase_06 AC 520 ms
27,764 KB
testcase_07 AC 417 ms
27,760 KB
testcase_08 AC 594 ms
27,748 KB
testcase_09 AC 561 ms
28,008 KB
testcase_10 AC 777 ms
28,040 KB
testcase_11 AC 775 ms
28,060 KB
testcase_12 AC 778 ms
28,044 KB
testcase_13 AC 467 ms
27,528 KB
testcase_14 AC 25 ms
4,400 KB
testcase_15 AC 221 ms
27,628 KB
testcase_16 AC 236 ms
27,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class RangeMinimumQuery
{
private:
    int n;
    vector<int> data;
    int query(int a, int b, int k, int l, int r){
        if(r < a || b < l)
            return INT_MAX;
        if(a <= l && r <= b)
            return data[k];
        int x = query(a, b, k*2+1, l, (l+r)/2);
        int y = query(a, b, k*2+2, (l+r+1)/2, r);
        return min(x, y);
    }
public:
    RangeMinimumQuery(int n0){ // コンストラクタ(要素数を指定)
        n = 1;
        while(n < n0)
            n *= 2;
        data.assign(2*n-1, INT_MAX);
    }
    RangeMinimumQuery(vector<int> vi){ // コンストラクタ(配列を指定)
        int n0 = vi.size();
        n = 1;
        while(n < n0)
            n *= 2;
        data.assign(2*n-1, INT_MAX);
        for(int i=0; i<n0; ++i)
            data[i+n-1] = vi[i];
        for(int i=n-2; i>=0; --i)
            data[i] = min(data[i*2+1], data[i*2+2]);
    }
    void update(int k, int x){ // k番目の要素をxに変更する
        k += n - 1;
        data[k] = x;
        while(k > 0){
            k = (k - 1) / 2;
            data[k] = min(data[k*2+1], data[k*2+2]);
        }
    }
    int query(int a, int b){ // 区間[a,b]の最小値を返す
        return query(a, b, 0, 0, n-1);
    }
};

int main()
{
    int n;
    cin >> n;
    vector<pair<string, int> > v(n);
    for(int i=0; i<n; ++i){
        cin >> v[i].first;
        v[i].second = i;
    }
    sort(v.begin(), v.end());
    vector<int> index(n);
    for(int i=0; i<n; ++i)
        index[v[i].second] = i;

    vector<int> len(n-1, 0);
    for(int i=0; i<n-1; ++i){
        int maxLen = min(v[i].first.size(), v[i+1].first.size());
        while(len[i] < maxLen && v[i].first[len[i]] == v[i+1].first[len[i]])
            ++ len[i];
    }
    RangeMinimumQuery rmq(len);

    int m;
    long long x, d;
    cin >> m >> x >> d;
    vector<int> a(m), b(m);
    for(int i=0; i<m; ++i){
        a[i] = (int)(x / (n - 1));
        b[i] = (int)(x % (n - 1));
        if(a[i] > b[i])
            swap(a[i], b[i]);
        else
            ++ b[i];
        x = (x + d) % (n * (n - 1LL));
    }

    long long ans = 0;
    for(int i=0; i<m; ++i){
        int a2 = index[a[i]];
        int b2 = index[b[i]];
        if(a2 > b2)
            swap(a2, b2);
        ans += rmq.query(a2, b2 - 1);
    }
    cout << ans << endl;

    return 0;
}
0