結果

問題 No.515 典型LCP
ユーザー paruparu
提出日時 2017-05-05 23:40:37
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 906 bytes
コンパイル時間 2,730 ms
コンパイル使用メモリ 54,512 KB
実行使用メモリ 9,504 KB
最終ジャッジ日時 2023-10-12 10:28:20
合計ジャッジ時間 4,388 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
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;
    long i[100001], j[100001];
    for (int k = 0; k < M; k++) {
        i[k] = (x / (N - 1)) + 1;
        j[k] = (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