結果

問題 No.515 典型LCP
ユーザー paruparu
提出日時 2017-05-05 23:45:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 928 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 63,388 KB
実行使用メモリ 115,680 KB
最終ジャッジ日時 2023-10-12 10:30:52
合計ジャッジ時間 16,275 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 TLE -
testcase_03 AC 4 ms
6,208 KB
testcase_04 AC 4 ms
6,260 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 AC 653 ms
58,256 KB
testcase_11 AC 737 ms
58,564 KB
testcase_12 AC 733 ms
59,764 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

long LCP (string l, string k) {
    long res = 0;
    for (int i = 0; i < min(l.size(), k.size()); i++) {
        if (l[i] != k[i]) {
            break;
        }
        else {
            res += 1;
        }
    }
    return res;
}

int main () {
    int N;
    cin >> N;
    string s[100001];
    for (int i = 0; i < N; i++) {
        cin >> s[i];
    }
    int M;
    long x, d;
    cin >> M >> x >> d;
    vector<long> i, j;
    for (int k = 0; k < M; k++) {
        i.push_back((x / (N - 1)) + 1);
        j.push_back((x % (N - 1)) + 1);
        if (i[k] > j[k]) {
            swap(i[k], j[k]);
        }
        else {
            j[k] = j[k] + 1;
        }
        i[k] -= 1;
        j[k] -= 1;
        x = (x + d) % (N * (N - 1));
    }
    long res = 0;
    for (int k = 0; k < M; k++) {
        res += LCP(s[i[k]], s[j[k]]);
    }
    cout << res << endl;
}
0