結果

問題 No.2210 equence Squence Seuence
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-02-11 13:15:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,098 bytes
コンパイル時間 4,731 ms
コンパイル使用メモリ 208,784 KB
実行使用メモリ 8,012 KB
最終ジャッジ日時 2023-09-22 11:11:12
合計ジャッジ時間 18,023 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 358 ms
4,580 KB
testcase_07 AC 1,256 ms
6,800 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1,548 ms
7,992 KB
testcase_14 WA -
testcase_15 AC 1,292 ms
7,860 KB
testcase_16 AC 1,503 ms
7,792 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 AC 863 ms
6,808 KB
testcase_24 AC 588 ms
5,952 KB
testcase_25 AC 763 ms
6,540 KB
testcase_26 AC 1,043 ms
7,528 KB
testcase_27 AC 226 ms
4,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
template <class T>
using vec = vector<T>;

struct rollhash_mod {
   public:
    // [2, MOD - 2]のbaseを乱数として生成
    static ll genBase() {
        random_device seed;     // 非決定的な乱数
        mt19937_64 mt(seed());  // メルセンヌ・ツイスタ 64bit
        uniform_int_distribution<ll> randbase(2LL, MOD - 2);
        return randbase(mt);
    }
    // べき乗のmod(tableを用意せずその場でやってるのでlog(beki)かかる)
    constexpr static ll power(ll base, ll beki) {
        rollhash_mod curbekiMod(base);
        rollhash_mod ret(1);
        while(beki > 0) {
            if(beki & 1) ret *= curbekiMod;
            curbekiMod *= curbekiMod;
            beki >>= 1;
        }
        return ret.val();
    }

    constexpr rollhash_mod(ll x = 0) : value(calcMod(x)) {}

    constexpr ll val() const { return value; }

    constexpr rollhash_mod &operator+=(const rollhash_mod &a) {
        if((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    constexpr rollhash_mod &operator-=(const rollhash_mod &a) {
        *this += (MOD - a.value);
        return *this;
    }
    constexpr rollhash_mod &operator*=(const rollhash_mod &a) {
        value = ((__int128_t)value * a.value) % MOD;
        return *this;
    }
    constexpr rollhash_mod operator+(const rollhash_mod &a) {
        rollhash_mod cpy(*this);
        return cpy += a;
    }
    constexpr rollhash_mod operator-(const rollhash_mod &a) {
        rollhash_mod cpy(*this);
        return cpy -= a;
    }
    constexpr rollhash_mod operator*(const rollhash_mod &a) {
        rollhash_mod cpy(*this);
        return cpy *= a;
    }
    constexpr bool operator==(const rollhash_mod & a){
        return value == a.value;
    }

   private:
    ll value;  // 中で保持しておくmod
    constexpr static ll MOD = (1LL << 61) - 1;
    constexpr static ll calcMod(const ll &x) {
        ll cur = x >> 61;
        if((cur += (x & MOD)) >= MOD) cur -= MOD;
        return cur;
    }
};

int N, K;
vec<int> A;
vec<rollhash_mod> basebeki_table, front_table;

// X_iの先頭k文字の接頭辞
rollhash_mod X_i_prefix(int i, int k) {
    assert(0 <= i && i <= N - 1);
    assert(0 <= k && k <= N - 1);
    if(i >= k) return front_table[k];
    rollhash_mod latter = front_table[k + 1] - front_table[i + 1] * basebeki_table[k - i - 1];
    rollhash_mod former = front_table[i];
    return latter + former;
}

// X_iとX_jの共通接頭辞の長さを二分探索で求める
int prefix_len(int i, int j){
    int l = 0, r = N;
    while(r - l > 1){
        int m = (l + r) / 2;
        if(X_i_prefix(i, m) == X_i_prefix(j, m)) l = m;
        else r = m;
    }
    return l;
}

// X_iとX_jのうち辞書順でiが小さければtrue
bool dict_cmp(int i, int j){
    int len = prefix_len(i, j);
    // 完全一致
    if(len == N - 1) return false;
    int X_i_num = 0, X_j_num = 0;
    if(len < i) X_i_num = A[len];
    else X_i_num = A[len + 1];
    if(len < j) X_j_num = A[len];
    else X_j_num = A[len + 1];
    return X_i_num < X_j_num;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    A = vec<int>(N);
    for(int &a : A) cin >> a;
    // baseのべきのtableを予め作る
    ll base = rollhash_mod::genBase();
    basebeki_table = vec<rollhash_mod>(N + 1, 1);
    for(int i = 1; i <= N; ++i) {
        basebeki_table[i] = basebeki_table[i - 1] * base;
    }
    // Aの接頭辞[0,i)のmodを求めておく
    front_table = vec<rollhash_mod>(N + 1, 0);
    for(int i = 1; i <= N; ++i) {
        front_table[i] = front_table[i - 1] * base + A[i - 1];
    }
    vec<int> permu(N);
    for(int i = 0; i < N; ++i){
        permu[i] = i;
    }
    sort(all(permu), dict_cmp);
    int ansIndex = permu[K - 1];
    for(int i = 0; i < N; i++){
        if(i != ansIndex) cout << A[i] << " ";
    }
    cout << "\n";
}
0