結果

問題 No.2626 Similar But Different Name
ユーザー coindarwcoindarw
提出日時 2024-02-09 23:37:08
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 378 ms / 3,000 ms
コード長 7,230 bytes
コンパイル時間 5,474 ms
コンパイル使用メモリ 312,652 KB
実行使用メモリ 56,164 KB
最終ジャッジ日時 2024-09-28 16:37:39
合計ジャッジ時間 12,542 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,820 KB
testcase_04 AC 1 ms
6,820 KB
testcase_05 AC 2 ms
6,816 KB
testcase_06 AC 2 ms
6,820 KB
testcase_07 AC 2 ms
6,820 KB
testcase_08 AC 2 ms
6,820 KB
testcase_09 AC 2 ms
6,816 KB
testcase_10 AC 3 ms
6,816 KB
testcase_11 AC 4 ms
6,820 KB
testcase_12 AC 3 ms
6,816 KB
testcase_13 AC 4 ms
6,820 KB
testcase_14 AC 4 ms
6,816 KB
testcase_15 AC 4 ms
6,816 KB
testcase_16 AC 4 ms
6,816 KB
testcase_17 AC 3 ms
6,816 KB
testcase_18 AC 374 ms
56,164 KB
testcase_19 AC 66 ms
31,620 KB
testcase_20 AC 60 ms
31,596 KB
testcase_21 AC 64 ms
31,536 KB
testcase_22 AC 373 ms
43,488 KB
testcase_23 AC 362 ms
43,512 KB
testcase_24 AC 358 ms
40,388 KB
testcase_25 AC 357 ms
41,500 KB
testcase_26 AC 359 ms
43,676 KB
testcase_27 AC 359 ms
43,756 KB
testcase_28 AC 362 ms
42,276 KB
testcase_29 AC 354 ms
40,308 KB
testcase_30 AC 354 ms
41,656 KB
testcase_31 AC 359 ms
43,004 KB
testcase_32 AC 358 ms
43,752 KB
testcase_33 AC 361 ms
43,900 KB
testcase_34 AC 347 ms
40,436 KB
testcase_35 AC 378 ms
43,032 KB
testcase_36 AC 356 ms
40,292 KB
testcase_37 AC 376 ms
56,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifdef ONLINE_JUDGE
#include <bits/stdc++.h>

#include <atcoder/all>
#else
#include <mylibs/all.h>
#endif

using ll = long long;
using lll = __int128_t;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define length(v) ((int)(v).size())
constexpr int inf = 2'000'000'000;
constexpr ll linf = 4'000'000'000'000'000'000, M7 = 1'000'000'007, M9 = 998'244'353;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;

// clang-format off
#define Vec(type, ...) __make_vec<type>(__VA_ARGS__)
template <class T> vector<T> __make_vec(size_t a) {return vector<T>(a);}template <class T, class... Ts>
auto __make_vec(size_t a, Ts... ts) {return vector<decltype(__make_vec<T>(ts...))>(a, __make_vec<T>(ts...));}
#define VecI(init, type, ...) __make_vecI<type, init>(__VA_ARGS__)
template <class T, T init>vector<T> __make_vecI(size_t a) {return vector<T>(a, init);}
template <class T, T init, class... Ts>
auto __make_vecI(size_t a, Ts... ts) {return vector<decltype(__make_vecI<T, init>(ts...))>(a, __make_vecI<T, init>(ts...));}

template <typename T, typename U>inline ostream& operator<<(ostream& os, const pair<T, U>& p) noexcept {return os << p.first << " " << p.second;}
inline ostream& operator<<(ostream& os, const modint& m) noexcept { return os << m.val(); }
template <int M>inline ostream& operator<<(ostream& os, const static_modint<M>& m) noexcept { return os << m.val(); }

template <typename T> struct is_static_modint : std::false_type {}; template <int MOD> struct is_static_modint<static_modint<MOD>> : std::true_type {};
template <template <typename...> typename C, typename Number>concept MyContainer = std::is_same_v<C<Number>, std::vector<Number>> || std::is_same_v<C<Number>, std::deque<Number>> || std::is_same_v<C<Number>, std::set<Number>> || std::is_same_v<C<Number>, std::unordered_set<Number>> || std::is_same_v<C<Number>, std::unordered_multiset<Number>> || std::is_same_v<C<Number>, std::multiset<Number>>;
template <typename Number>concept MyNumber = std::is_same_v<Number, int> || std::is_same_v<Number, ll> || std::is_same_v<Number, char> || std::is_same_v<Number, modint> || is_static_modint<Number>::value;
template <template <typename...> typename C, typename Number>concept MyContainerNumber = MyContainer<C, Number> && MyNumber<Number>;
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>concept MyNestedContainerNumber = MyContainer<OutCon, InCon<Number>> && MyContainerNumber<InCon, Number>;
template <template <typename...> typename C, typename Number>requires MyContainerNumber<C, Number>std::ostream& operator<<(std::ostream& os, const C<Number>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << ' ' << *itr;}return os;}
template <template <typename...> typename OutCon, template <typename...> typename InCon, typename Number>requires MyNestedContainerNumber<OutCon, InCon, Number>std::ostream& operator<<(std::ostream& os, const OutCon<InCon<Number>>& t) {auto itr = t.begin();auto end = t.end();if (itr != end) {os << *itr++;for (; itr != end; ++itr) os << '\n' << *itr;}return os;}
template <typename T, typename U>istream& operator>>(istream& is, pair<T, U>& p) {return is >> p.first >> p.second;}
template <typename T>istream& operator>>(istream& is, vector<T>& v) {for (auto& e : v) is >> e;return is;}
void inp() {}
template <typename T, typename... Args>void inp(T& a, Args&... args) {cin >> a, inp(args...);}
template <typename T>void inp1(vector<T>& v, int offset = 1, int len = -1) {if (len == -1) len = int(v.size()) - offset;assert(offset >= 0 && len >= 0);for (int i = offset; i < offset + len; ++i) cin >> v[i];}
template <typename T>void oup(const T& a) {cout << a << "\n";}
template <typename T, typename... Args>void oup(const T& a, const Args&... args) {cout << a << " ", oup(args...);}

inline string YESNO(bool cond) { return cond ? "YES" : "NO"; }inline string yesno(bool cond) { return cond ? "yes" : "no"; }inline string YesNo(bool cond) { return cond ? "Yes" : "No"; }
inline auto add1(auto vec, ll offset = 1) {for (auto& e : vec) e += offset;return vec;}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>void debug_out(T t) {cerr << t << "\n";}
template <typename T, typename... Args>void debug_out(T t, Args... args) {cerr << t << ", ";debug_out(args...);}
#endif

#ifdef ONLINE_JUDGE
#define todo(...) static_assert(false)
#else
#define todo(...)
#endif
// clang-format on

const long long M1 = 998244353;
const long long M2 = 1000000007;
const long long B1 = 10007;
const long long B2 = 9973;

template <long long MOD1, long long MOD2, long long BASE1, long long BASE2>
class RollingHash {
   private:
    vector<ll> hash1, power1, hash2, power2;
    using hash = pair<ll, ll>;
    int size;

   public:
    RollingHash() {}
    RollingHash(const string& str) {
        size = str.size();
        hash1 = vector<ll>(size + 1, 0);
        hash2 = vector<ll>(size + 1, 0);
        power1 = vector<ll>(size + 1, 1);
        power2 = vector<ll>(size + 1, 1);
        for (int i = 1; i <= size; i++) {
            hash1[i] = (hash1[i - 1] + str[i - 1]) * BASE1 % MOD1;
            hash2[i] = (hash2[i - 1] + str[i - 1]) * BASE2 % MOD2;
            power1[i] = power1[i - 1] * BASE1 % MOD1;
            power2[i] = power2[i - 1] * BASE2 % MOD2;
        }
    }
    hash get(int l, int r) { return make_pair(((hash1[r] - hash1[l] * power1[r - l]) % MOD1 + MOD1) % MOD1, ((hash2[r] - hash2[l] * power2[r - l]) % MOD2 + MOD2) % MOD2); }

    hash concat(hash h1, hash h2, int h2_length) { return make_pair((h1.first * power1[h2_length] + h2.first) % MOD1, (h1.second * power2[h2_length] + h2.second) % MOD2); }
};

using RH = RollingHash<M1, M2, B1, B2>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, k;
    inp(n, m, k);
    string s, t;
    inp(s, t);

    string ls, lt;
    rep(i, n) {
        if ('A' <= s[i] && s[i] <= 'Z') ls += char(s[i] - 'A' + 'a');
        else ls += s[i];
    }
    rep(i, m) {
        if ('A' <= t[i] && t[i] <= 'Z') lt += char(t[i] - 'A' + 'a');
        else lt += t[i];
    }

    vector<ll> sU(n), tL(m);
    rep(i, n) {
        if ('A' <= s[i] && s[i] <= 'Z') sU[i] = 1e6;
        else sU[i] = 1;
    }
    rep(i, m) {
        if ('a' <= t[i] && t[i] <= 'z') tL[i] = 1;
        else tL[i] = 1e6;
    }
    reverse(all(tL));
    auto cnv = convolution_ll(sU, tL);
    for (ll& e : cnv) e = (e / ll(1e6)) % ll(1e6);
    vector<ll> v(cnv.begin() + m - 1, cnv.end());

    RH rh1(ls), rh2(lt);
    auto h2 = rh2.get(0, m);
    int ans = 0;
    rep(i, n - m + 1) {
        auto h1 = rh1.get(i, i + m);
        if (h1 == h2) {
            if (1 <= v[i] && v[i] <= k) ans++;
        }
    }
    oup(ans);
    return 0;
}
0