提出 #74689737


ソースコード 拡げる

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG 
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
using namespace __gnu_pbds;
using ll = long long; using mint=modint998244353; using ld = long double; 
const ll infl = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const vector<int> dx = {1, 0, -1, 0}; const vector<int> dy = {0, 1, 0, -1};
template<typename T> using vc = vector<T>; template<typename T> using vvc = vc<vc<T>>; template<typename T> using vvvc = vc<vvc<T>>;
using vi = vc<int>;  using vvi = vvc<int>; using vl = vc<ll>; using vvl = vvc<ll>; using vvvl = vvc<vl>; using vvvvl = vvc<vvl>;
using vs = vc<string>; using vvs = vvc<string>; using P = pair<ll, ll>;
#define nrep(i,n) for (ll i = 0; i < (n); ++i)
#define nfor(i,s,n) for(ll i=s;i<n;i++)//i=s,s+1...n-1 ノーマルfor
template<class T> using pq = priority_queue<T, vc<T>>;//★大きい順に取り出す コスト,頂点 bfs系で使う 小さい順じゃないですABC305E
template<class T> using pq_g = priority_queue<T, vc<T>, greater<T>>;//小さい順に取り出す ダイクストラ法で使う

// 単なるcout関数
template<typename T>
void print(const T& n) {
    cout << n << "\n";
}
// デバッグ出力ユーティリティ
// 基本型(数値系)
template<typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
void debug_print(const T& v) { cout << v; }
// string
inline void debug_print(const std::string& s) { cout << s; }
inline void debug_print(const char* s) { cout << s; }
// pair
template<typename A, typename B>
void debug_print(const std::pair<A, B>& p) {
    cout << "{";
    debug_print(p.first);
    cout << ", ";
    debug_print(p.second);
    cout << "}";
}
// queue
template<typename T, typename Cont>
void debug_print(const std::queue<T, Cont>& q) {
    auto q2 = q;
    cout << "queue[";
    while (!q2.empty()) {
        debug_print(q2.front());
        q2.pop();
        if (!q2.empty()) cout << ", ";
    }
    cout << "]";
}
// stack
template<typename T, typename Cont>
void debug_print(const std::stack<T, Cont>& s) {
    auto s2 = s;
    cout << "stack[";
    std::vector<T> tmp;
    while (!s2.empty()) {
        tmp.push_back(s2.top());
        s2.pop();
    }
    for (size_t i = 0; i < tmp.size(); ++i) {
        debug_print(tmp[i]);
        if (i + 1 != tmp.size()) cout << ", ";
    }
    cout << "]";
}
// priority_queue
template<typename T, typename Cont, typename Comp>
void debug_print(const std::priority_queue<T, Cont, Comp>& pq) {
    auto q2 = pq;
    cout << "priority_queue[";
    std::vector<T> tmp;
    while (!q2.empty()) {
        tmp.push_back(q2.top());
        q2.pop();
    }
    for (size_t i = 0; i < tmp.size(); ++i) {
        debug_print(tmp[i]);
        if (i + 1 != tmp.size()) cout << ", ";
    }
    cout << "]";
}
// イテレータを持つコンテナ(string, queue, stack, priority_queue 以外)
template<typename T>
auto debug_print(const T& c) -> decltype(std::begin(c), void()) {
    cout << "[";
    auto it = std::begin(c);
    while (it != std::end(c)) {
        debug_print(*it);
        if (++it != std::end(c)) cout << ", ";
    }
    cout << "]";
}
// デバッグ用のマクロ(変数名と値を一緒に出力)
#ifndef ONLINE_JUDGE
#define DEBUG(...) cerr << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); cerr << endl;
#else
#define DEBUG(...)
#endif  
// 1次元vector出力関数
template<typename T>
void vc_cout(const vector<T>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        cout << v[i];
        if (i + 1 != v.size()) cout << " ";
    }
    cout << "\n";
}
// 2次元vector出力関数
template<typename T>
void vv_cout(const vector<vector<T>>& v) {
    for (size_t i = 0; i < v.size(); ++i) {
        for (size_t j = 0; j < v[i].size(); ++j) {
            cout << v[i][j];
            if (j + 1 != v[i].size()) cout << " ";
        }
        cout << "\n";
    }
}
// `vector<string>` 用のオーバーロード: 各文字列をそのまま1行で出力する
void vv_cout(const vector<string>& v) {
    for (const auto& s : v) cout << s << "\n";
}
/* 
    ********************************************************** ここまでテンプレ **********************************************************
*/
string S,T;

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin >> S >> T;
    ll N = S.size();
    ll M = T.size();
    vc<deque<ll>> t_id(M);
    nrep(i, M) {
        nrep(j, N) {
            if(S[j] == T[i]) t_id[i].push_back(j);
        }
    }
    DEBUG(t_id);
    ll mx;
    if(!t_id[0].empty()) mx = t_id[0].front();
    else mx = 1e18;
    nfor(i, 1, M) {
        while(!t_id[i].empty() && t_id[i].front() <= mx) t_id[i].pop_front();
        if(!t_id[i].empty()) mx = t_id[i].front();
        else mx = 1e18;
    }
    DEBUG(t_id);
    ll ans = 0;
    bool empty = false;
    nrep(j, M) {
        if(t_id[j].empty()) empty = true;
    } 
    nrep(i, N) {
        DEBUG(i);
        DEBUG(t_id);
        DEBUG(empty);
        if(!empty) {
            ll r = t_id.back().front();
            ans += r-i;
        } else {
            ans += N-i;
        }
        DEBUG(t_id);
        if(!t_id[0].empty() && t_id[0].front() == i) t_id[0].pop_front();
        nrep(j, M) {
            if(t_id[j].empty()) empty = true;
        } 
        if(!empty) {
            DEBUG(t_id);
            ll mx = t_id[0].front();
            nfor(j, 1, M) {
                DEBUG(j);
                DEBUG(mx);
                while(!t_id[j].empty() && t_id[j].front() <= mx) t_id[j].pop_front();

                if(!t_id[j].empty()) mx = t_id[j].front();
                else mx = 1e18;
            }
        }
        nrep(j, M) {
            if(t_id[j].empty()) empty = true;
        }     
    }
    print(ans);

}

提出情報

提出日時
問題 D - No-Subsequence Substring
ユーザ kuruma_zensoku
言語 C++23 (GCC 15.2.0)
得点 400
コード長 6224 Byte
結果 AC
実行時間 79 ms
メモリ 85732 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 56
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3620 KiB
00_sample_01.txt AC 1 ms 3612 KiB
00_sample_02.txt AC 1 ms 3664 KiB
01_random_03.txt AC 9 ms 4520 KiB
01_random_04.txt AC 14 ms 5220 KiB
01_random_05.txt AC 5 ms 3988 KiB
01_random_06.txt AC 8 ms 4264 KiB
01_random_07.txt AC 6 ms 3932 KiB
01_random_08.txt AC 11 ms 4776 KiB
01_random_09.txt AC 17 ms 5656 KiB
01_random_10.txt AC 13 ms 4956 KiB
01_random_11.txt AC 21 ms 6232 KiB
01_random_12.txt AC 5 ms 4024 KiB
01_random_13.txt AC 5 ms 4056 KiB
01_random_14.txt AC 15 ms 5332 KiB
01_random_15.txt AC 17 ms 5544 KiB
01_random_16.txt AC 20 ms 6152 KiB
01_random_17.txt AC 14 ms 5216 KiB
01_random_18.txt AC 5 ms 4168 KiB
01_random_19.txt AC 22 ms 6236 KiB
01_random_20.txt AC 14 ms 5204 KiB
01_random_21.txt AC 6 ms 4056 KiB
01_random_22.txt AC 20 ms 6120 KiB
01_random_23.txt AC 22 ms 6312 KiB
01_random_24.txt AC 34 ms 14164 KiB
01_random_25.txt AC 70 ms 31140 KiB
01_random_26.txt AC 14 ms 5928 KiB
01_random_27.txt AC 24 ms 10460 KiB
01_random_28.txt AC 24 ms 8556 KiB
01_random_29.txt AC 28 ms 13000 KiB
01_random_30.txt AC 16 ms 7020 KiB
01_random_31.txt AC 17 ms 8020 KiB
01_random_32.txt AC 6 ms 5268 KiB
01_random_33.txt AC 64 ms 33252 KiB
01_random_34.txt AC 53 ms 26580 KiB
01_random_35.txt AC 79 ms 39716 KiB
01_random_36.txt AC 66 ms 34020 KiB
01_random_37.txt AC 40 ms 20892 KiB
01_random_38.txt AC 40 ms 20836 KiB
01_random_39.txt AC 43 ms 22536 KiB
01_random_40.txt AC 10 ms 6820 KiB
01_random_41.txt AC 14 ms 5716 KiB
01_random_42.txt AC 20 ms 14876 KiB
01_random_43.txt AC 3 ms 4124 KiB
01_random_44.txt AC 11 ms 7164 KiB
01_random_45.txt AC 6 ms 7196 KiB
01_random_46.txt AC 15 ms 7144 KiB
01_random_47.txt AC 9 ms 4972 KiB
01_random_48.txt AC 3 ms 4972 KiB
01_random_49.txt AC 42 ms 46872 KiB
01_random_50.txt AC 18 ms 22676 KiB
01_random_51.txt AC 78 ms 85732 KiB
01_random_52.txt AC 3 ms 5204 KiB
01_random_53.txt AC 1 ms 3612 KiB
01_random_54.txt AC 1 ms 3620 KiB
01_random_55.txt AC 1 ms 3640 KiB