QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#224342 | #7618. Pattern Search | ucup-team987# | WA | 0ms | 3668kb | C++23 | 3.2kb | 2023-10-23 01:26:58 | 2023-10-23 01:26:58 |
Judging History
answer
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
namespace {
void solve() {
string s, t;
scan(s, t);
array<int, 26> a{};
for (char c : s) {
++a[c - 'a'];
}
array<int, 26> b{};
for (char c : t) {
++b[c - 'a'];
}
int n = len(s);
int m = len(t);
auto check = [&](int mid) -> bool {
for (int k : rep1(m)) {
int qb = m / k;
int r = m % k;
int qa = qb + (mid - 1);
int sum = 0;
int sum2 = 0;
int sum3 = 0;
for (int i : rep(26)) {
int t = min(a[i] / qa, b[i] / qb);
sum += t;
int t2 = min({a[i] - t * qa, b[i] - t * qb, t});
sum2 += t2;
sum3 += (t - t2) / (qb + 1) * qb + (t - t2) % (qb + 1);
}
if (sum < k) {
continue;
}
if (r <= sum2) {
return true;
}
if (r - sum2 <= min((sum - k) * qb, sum3)) {
return true;
}
}
return false;
};
int ok = 0;
int ng = n + 1;
while (ok + 1 < ng) {
int mid = midpoint(ok, ng);
(check(mid) ? ok : ng) = mid;
}
print(ok);
}
} // namespace
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
scan(t);
while (t--) {
solve();
}
}
#else // __INCLUDE_LEVEL__
#include <bits/stdc++.h>
using namespace std;
namespace std {
template <class T1, class T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
return is >> p.first >> p.second;
}
template <class... Ts>
istream& operator>>(istream& is, tuple<Ts...>& t) {
return apply([&is](auto&... xs) -> istream& { return (is >> ... >> xs); }, t);
}
template <class R, enable_if_t<!is_convertible_v<R, string>>* = nullptr>
auto operator>>(istream& is, R&& r) -> decltype(is >> *begin(r)) {
for (auto&& e : r) {
is >> e;
}
return is;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
return os << p.first << ' ' << p.second;
}
template <class... Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
auto f = [&os](const auto&... xs) -> ostream& {
[[maybe_unused]] auto sep = "";
((os << exchange(sep, " ") << xs), ...);
return os;
};
return apply(f, t);
}
template <class R, enable_if_t<!is_convertible_v<R, string_view>>* = nullptr>
auto operator<<(ostream& os, R&& r) -> decltype(os << *begin(r)) {
auto sep = "";
for (auto&& e : r) {
os << exchange(sep, " ") << e;
}
return os;
}
} // namespace std
template <class... Ts>
void scan(Ts&&... xs) {
(cin >> ... >> xs);
}
template <class... Ts>
void print(Ts&&... xs) {
cout << tie(xs...) << '\n';
}
inline auto rep(int l, int r) { return views::iota(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); }
inline auto per(int l, int r) { return rep(l, r) | views::reverse; }
inline auto per(int n) { return per(0, n); }
inline auto per1(int l, int r) { return per(l, r + 1); }
inline auto per1(int n) { return per(1, n + 1); }
inline auto len = ranges::ssize;
#endif // __INCLUDE_LEVEL__
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
2 bajkaaall aal abca cba
output:
2 1
result:
ok 2 number(s): "2 1"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
input:
16 a a a b b a aa a ab aa ab b ab c aaz az abcde edcba aaaaaaaaaaaabbb aaaaaaaaabb aaaaaazz az aaaaaaaaaz zzzzz gggggggggggggggggggge ggggeeee hyphyphyphyphyphyphyphyphyphyphyphyp eeeeeeeeee hyphyphyphyphyphyphyphyphyphyphyphype eeteeteeteet aaaabbbbbbcccccccc aaabbbbbcccccc
output:
1 0 0 2 0 1 0 1 1 1 2 0 0 0 0 1
result:
wrong answer 10th numbers differ - expected: '2', found: '1'