結果

問題 No.515 典型LCP
ユーザー PachicobuePachicobue
提出日時 2017-05-05 23:39:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,913 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 173,388 KB
実行使用メモリ 148,872 KB
最終ジャッジ日時 2023-10-12 11:09:22
合計ジャッジ時間 6,177 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
using ll = long long;
constexpr ll MOD = 1000000007;

using psi = pair<string, int>;
constexpr int MAX = 100000;
string str[MAX];

unordered_map<ll, ll> mpp[MAX];

inline int lcp(ll i, ll j)
{
    if (mpp[i].find(j) != mpp[i].end()) {
        return mpp[i].at(j);
    }
    const string& s1 = str[i];
    const string& s2 = str[j];
    int cnt = 0;
    rep(k, min(s1.size(), s2.size()))
    {
        if (s1[k] != s2[k]) {
            break;
        } else {
            cnt++;
        }
    }
    mpp[i][j] = cnt;
    return cnt;
}


int main()
{
    ll N;
    cin >> N;

    rep(i, N)
    {
        cin >> str[i];
    }

    ll M, x, d;
    cin >> M >> x >> d;
    ll sum = 0;
    rep(i, M)
    {
        ll I = (x / (N - 1)) + 1;
        ll J = (x % (N - 1)) + 1;
        if (I > J) {
            swap<ll>(I, J);
        } else {
            J = J + 1;
        }
        const ll t = lcp(I - 1, J - 1);
        sum += t;
        x = (x + d) % (N * (N - 1));
    }

    cout << sum << endl;

    return 0;
}
0