結果

問題 No.2626 Similar But Different Name
ユーザー risujirohrisujiroh
提出日時 2024-02-09 22:04:37
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 3,000 ms
コード長 7,951 bytes
コンパイル時間 4,644 ms
コンパイル使用メモリ 313,740 KB
実行使用メモリ 41,032 KB
最終ジャッジ日時 2024-02-09 22:04:47
合計ジャッジ時間 8,610 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 3 ms
6,676 KB
testcase_17 AC 3 ms
6,676 KB
testcase_18 AC 167 ms
41,032 KB
testcase_19 AC 42 ms
20,572 KB
testcase_20 AC 37 ms
20,572 KB
testcase_21 AC 37 ms
20,572 KB
testcase_22 AC 158 ms
35,712 KB
testcase_23 AC 162 ms
35,704 KB
testcase_24 AC 178 ms
34,472 KB
testcase_25 AC 173 ms
34,900 KB
testcase_26 AC 163 ms
35,680 KB
testcase_27 AC 159 ms
35,804 KB
testcase_28 AC 159 ms
35,204 KB
testcase_29 AC 158 ms
34,476 KB
testcase_30 AC 157 ms
34,884 KB
testcase_31 AC 179 ms
35,508 KB
testcase_32 AC 158 ms
35,760 KB
testcase_33 AC 160 ms
35,804 KB
testcase_34 AC 156 ms
34,484 KB
testcase_35 AC 167 ms
35,520 KB
testcase_36 AC 166 ms
34,484 KB
testcase_37 AC 170 ms
41,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from main.cpp:3:
main.cpp: In instantiation of 'std::array<std::vector<unsigned int>, 2> RollingHash<2147482819>::base':
main.cpp:78:26:   required from 'RollingHash<P>::RollingHash(Iterator, Iterator) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >; unsigned int P = 2147482819]'
main.cpp:20:50:   required from here
main.cpp:71:65: warning: narrowing conversion of '(RollingHash<2147482819>::rng_.std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::operator()() % 2147482819)' from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'unsigned int' [-Wnarrowing]
   71 |   static inline std::array base{std::vector<uint32_t>{1, rng_() % P},
      |                                                          ~~~~~~~^~~
main.cpp:71:65: warning: narrowing conversion of '(RollingHash<2147482819>::rng_.std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::operator()() % 2147482819)' from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'unsigned int' [-Wnarrowing]
main.cpp:72:65: warning: narrowing conversion of '(RollingHash<2147482819>::rng_.std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::operator()() % 2147482819)' from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'unsigned int' [-Wnarrowing]
   72 |                                 std::vector<uint32_t>

ソースコード

diff #

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

namespace {

void solve() {
  int n, m, k;
  scan(n, m, k);
  std::string s, t;
  scan(s, t);
  auto s_lower = s;
  for (char& c : s_lower) {
    c = std::tolower(c);
  }
  auto t_lower = t;
  for (char& c : t_lower) {
    c = std::tolower(c);
  }
  RollingHash rh_s(s_lower.begin(), s_lower.end());
  RollingHash rh_t(t_lower.begin(), t_lower.end());
  std::basic_string<bool> ans(n - m + 1, true);
  for (const int i : rep(n - m + 1)) {
    ans[i] = rh_s.get(i, i + m) == rh_t.get(0, m);
  }
  using mint = atcoder::modint998244353;
  std::vector<mint> s_islower(n);
  std::vector<mint> s_isupper(n);
  for (const int i : rep(n)) {
    s_islower[i] = std::islower(s[i]) != 0;
    s_isupper[i] = std::isupper(s[i]) != 0;
  }
  std::vector<mint> t_islower(m);
  std::vector<mint> t_isupper(m);
  for (const int i : rep(m)) {
    t_islower[i] = std::islower(t[i]) != 0;
    t_isupper[i] = std::isupper(t[i]) != 0;
  }
  ranges::reverse(t_islower);
  ranges::reverse(t_isupper);
  auto v01 = atcoder::convolution(s_islower, t_isupper);
  auto v10 = atcoder::convolution(s_isupper, t_islower);
  for (const int i : rep(n - m + 1)) {
    const int d = (v01[i + m - 1] + v10[i + m - 1]).val();
    ans[i] &= 1 <= d && d <= k;
  }
  print(ranges::count(ans, true));
}

// カス

}  // namespace

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  solve();
}

#else  // __INCLUDE_LEVEL__

#include <bits/stdc++.h>

#include <atcoder/convolution>

template <uint32_t P = 2147482819>
struct RollingHash {
  static inline std::mt19937 rng_{
      uint32_t(std::chrono::steady_clock::now().time_since_epoch().count())};
  static inline std::array base{std::vector<uint32_t>{1, rng_() % P},
                                std::vector<uint32_t>{1, rng_() % P}};
  std::array<std::vector<uint32_t>, 2> h;
  RollingHash() { h[0] = h[1] = {0}; }
  template <class Iterator>
  RollingHash(Iterator first, Iterator last) {
    int n = std::distance(first, last);
    for (int z : {0, 1}) base[z].reserve(n + 1), h[z].reserve(n + 1);
    for (h[0] = h[1] = {0}; first != last;) push_back(*first++);
  }
  template <class T>
  void push_back(const T& a) {
    for (int z : {0, 1}) {
      h[z].push_back((uint64_t(h[z].back()) * base[z][1] + a) % P);
      while (base[z].size() < h[z].size())
        base[z].push_back(uint64_t(base[z].back()) * base[z][1] % P);
    }
  }
  void pop_back() {
    for (int z : {0, 1}) h[z].pop_back();
  }
  int get(int l, int r, int z) const {
    return (h[z][r] + uint64_t(P - h[z][l]) * base[z][r - l]) % P;
  }
  std::array<int, 2> get(int l, int r) const { return {get(l, r, 0), get(l, r, 1)}; }

  friend int lcp(const RollingHash& ha, int la, int ra, const RollingHash& hb, int lb, int rb) {
    int ok = 0, ng = std::min(ra - la, rb - lb) + 1;
    while (ng - ok > 1) {
      int mid = (ok + ng) / 2;
      (ha.get(la, la + mid) == hb.get(lb, lb + mid) ? ok : ng) = mid;
    }
    return ok;
  }
  friend int strcmp(const RollingHash& ha, int la, int ra, const RollingHash& hb, int lb, int rb) {
    int m = lcp(ha, la, ra, hb, lb, rb);
    if (la + m == ra && lb + m == rb) return 0;
    if (la + m == ra) return -1;
    if (lb + m == rb) return +1;
    return ha.get(la + m, la + m + 1, 0) - hb.get(lb + m, lb + m + 1, 0);
  }
};

template <class T, class U = T>
bool chmin(T& x, U&& y) {
  return y < x && (x = std::forward<U>(y), true);
}

template <class T, class U = T>
bool chmax(T& x, U&& y) {
  return x < y && (x = std::forward<U>(y), true);
}

template <std::signed_integral T = int>
T inf() {
  T ret;
  std::memset(&ret, 0x3f, sizeof(ret));
  return ret;
}

template <std::floating_point T>
T inf() {
  return std::numeric_limits<T>::infinity();
}

template <class T>
concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;

template <class T>
concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;

namespace std {

istream& operator>>(istream& is, Range auto&& r) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

istream& operator>>(istream& is, Tuple auto&& t) {
  return apply([&](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}

ostream& operator<<(ostream& os, Range auto&& r) {
  for (string_view sep = ""; auto&& e : r) {
    os << exchange(sep, " ") << e;
  }
  return os;
}

ostream& operator<<(ostream& os, Tuple auto&& t) {
  const auto f = [&](auto&... xs) -> ostream& {
    [[maybe_unused]] string_view sep = "";
    ((os << exchange(sep, " ") << xs), ...);
    return os;
  };
  return apply(f, t);
}

template <class T, atcoder::internal::is_modint_t<T>* = nullptr>
istream& operator>>(istream& is, T& x) {
  int v;
  is >> v;
  x = T::raw(v);
  return is;
}

template <class T, atcoder::internal::is_modint_t<T>* = nullptr>
ostream& operator<<(ostream& os, const T& x) {
  return os << x.val();
}

}  // namespace std

#define DEF_INC_OR_DEC(op) \
  auto& operator op(Range auto&& r) { \
    for (auto&& e : r) { \
      op e; \
    } \
    return r; \
  } \
  auto& operator op(Tuple auto&& t) { \
    std::apply([](auto&... xs) { (op xs, ...); }, t); \
    return t; \
  }

DEF_INC_OR_DEC(++)
DEF_INC_OR_DEC(--)

#undef DEF_INC_OR_DEC

void scan(auto&&... xs) { std::cin >> std::tie(xs...); }
void print(auto&&... xs) { std::cout << std::tie(xs...) << '\n'; }

#define FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)

template <class F>
class fix {
 public:
  explicit fix(F f) : f_(std::move(f)) {}

  decltype(auto) operator()(auto&&... xs) const { return f_(std::ref(*this), FWD(xs)...); }

 private:
  F f_;
};

template <class T>
concept LambdaExpr = std::is_placeholder_v<std::remove_cvref_t<T>> != 0 ||
                     std::is_bind_expression_v<std::remove_cvref_t<T>>;

auto operator++(LambdaExpr auto&& x, int) {
  return std::bind([](auto&& x) -> decltype(auto) { return FWD(x)++; }, FWD(x));
}

auto operator--(LambdaExpr auto&& x, int) {
  return std::bind([](auto&& x) -> decltype(auto) { return FWD(x)--; }, FWD(x));
}

#define DEF_UNARY_OP(op) \
  auto operator op(LambdaExpr auto&& x) { \
    return std::bind([](auto&& x) -> decltype(auto) { return op FWD(x); }, FWD(x)); \
  }

DEF_UNARY_OP(++)
DEF_UNARY_OP(--)
DEF_UNARY_OP(+)
DEF_UNARY_OP(-)
DEF_UNARY_OP(~)
DEF_UNARY_OP(!)
DEF_UNARY_OP(*)
DEF_UNARY_OP(&)

#undef DEF_UNARY_OP

#define DEF_BINARY_OP(op) \
  template <class T1, class T2> \
    requires LambdaExpr<T1> || LambdaExpr<T2> \
  auto operator op(T1&& x, T2&& y) { \
    return std::bind([](auto&& x, auto&& y) -> decltype(auto) { return FWD(x) op FWD(y); }, \
                     FWD(x), FWD(y)); \
  }

DEF_BINARY_OP(+=)
DEF_BINARY_OP(-=)
DEF_BINARY_OP(*=)
DEF_BINARY_OP(/=)
DEF_BINARY_OP(%=)
DEF_BINARY_OP(^=)
DEF_BINARY_OP(&=)
DEF_BINARY_OP(|=)
DEF_BINARY_OP(<<=)
DEF_BINARY_OP(>>=)
DEF_BINARY_OP(+)
DEF_BINARY_OP(-)
DEF_BINARY_OP(*)
DEF_BINARY_OP(/)
DEF_BINARY_OP(%)
DEF_BINARY_OP(^)
DEF_BINARY_OP(&)
DEF_BINARY_OP(|)
DEF_BINARY_OP(<<)
DEF_BINARY_OP(>>)
DEF_BINARY_OP(==)
DEF_BINARY_OP(!=)
DEF_BINARY_OP(<)
DEF_BINARY_OP(>)
DEF_BINARY_OP(<=)
DEF_BINARY_OP(>=)
DEF_BINARY_OP(&&)
DEF_BINARY_OP(||)

#undef DEF_BINARY_OP

template <class T1, class T2>
  requires LambdaExpr<T1> || LambdaExpr<T2>
auto at(T1&& x, T2&& y) {
  return std::bind([](auto&& x, auto&& y) -> decltype(auto) { return FWD(x)[FWD(y)]; }, FWD(x),
                   FWD(y));
}

template <int I>
auto get(LambdaExpr auto&& x) {
  return std::bind([](auto&& x) -> decltype(auto) { return std::get<I>(FWD(x)); }, FWD(x));
}

inline auto rep(int l, int r) { return std::views::iota(std::min(l, r), r); }
inline auto rep(int n) { return rep(0, n); }
inline auto rep1(int l, int r) { return rep(l, r + 1); }
inline auto rep1(int n) { return rep(1, n + 1); }

using namespace std::literals;
using namespace std::placeholders;

namespace ranges = std::ranges;
namespace views = std::views;

using i64 = std::int64_t;

#endif  // __INCLUDE_LEVEL__
0