結果

問題 No.2626 Similar But Different Name
ユーザー risujirohrisujiroh
提出日時 2024-02-09 22:04:37
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 175 ms / 3,000 ms
コード長 7,951 bytes
コンパイル時間 4,318 ms
コンパイル使用メモリ 312,988 KB
実行使用メモリ 41,040 KB
最終ジャッジ日時 2024-09-28 15:18:22
合計ジャッジ時間 8,332 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます
コンパイルメッセージ
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__
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0