結果

問題 No.1018 suffixsuffixsuffix
ユーザー tomatoma
提出日時 2020-04-03 22:51:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,255 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 171,372 KB
実行使用メモリ 7,752 KB
最終ジャッジ日時 2023-09-16 03:58:24
合計ジャッジ時間 8,518 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 136 ms
7,372 KB
testcase_10 AC 140 ms
7,432 KB
testcase_11 AC 147 ms
7,572 KB
testcase_12 AC 137 ms
7,500 KB
testcase_13 AC 138 ms
7,408 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 45 ms
4,928 KB
testcase_21 AC 47 ms
4,820 KB
testcase_22 WA -
testcase_23 AC 48 ms
4,856 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 159 ms
7,424 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 47 ms
4,860 KB
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

constexpr ll MAX_N = 1e5 + 10;
int n, k;
int sa[MAX_N + 1];
int mrank[MAX_N + 1];
int tmp[MAX_N + 1];
bool compare_sa(int i, int j) {
    if (mrank[i] != mrank[j])return mrank[i] < mrank[j];
    else {
        int ri = i + k <= n ? mrank[i + k] : -1;
        int rj = j + k <= n ? mrank[j + k] : -1;
        return ri < rj;
    }
}
void construct_sa(string S) {
    n = S.size();
    rep(i, n + 1) {
        sa[i] = i;
        mrank[i] = i < n ? S[i] : -1;
    }
    for (k = 1; k <= n; k *= 2) {
        sort(sa, sa + n + 1, compare_sa);
        tmp[sa[0]] = 0;
        for (int i = 1; i <= n; i++) {
            tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
        }
        for (int i = 0; i <= n; i++) {
            mrank[i] = tmp[i];
        }
    }
}

int main()
{
    ll N, M, Q;
    string s;
    cin >> N >> M >> Q >> s;
    vector<ll> K(Q);
    rep(i, Q)cin >> K[i];

    construct_sa(s);
    vector<ll> sa2;
    REP(i, 1, N + 1)sa2.push_back(N - 1 - sa[i]);
    //output(sa2);

    vector<ll> res;
    for (auto k : K) {
        k--;
        ll row = k / M, col = k % M;
        res.push_back(N * M - sa2[row] - col * N);
    }
    output(res);

    return 0;
}
0