QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224213#7618. Pattern Searchucup-team987#WA 0ms3528kbC++233.0kb2023-10-23 00:35:532023-10-23 00:35:54

Judging History

你现在查看的是最新测评结果

  • [2023-10-23 00:35:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2023-10-23 00:35:53]
  • 提交

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;
      for (int i : rep(26)) {
        int t = min(a[i] / qa, b[i] / qb);
        sum += t;
        sum2 += min(a[i] - t * qa, b[i] - t * qb);
      }
      if (sum < k) {
        continue;
      }
      if (r <= sum2) {
        return true;
      }
      if (r - sum2 <= int64_t(sum - k) * qa) {
        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: 3464kb

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: 3528kb

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
2
2
0
0
0
0
2

result:

wrong answer 16th numbers differ - expected: '1', found: '2'