QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224436#7618. Pattern Searchucup-team987#WA 0ms3640kbC++233.5kb2023-10-23 02:36:512023-10-23 02:36:51

Judging History

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

  • [2023-10-23 02:36:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3640kb
  • [2023-10-23 02:36:51]
  • 提交

answer

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

namespace {

void solve() {
#define int int64_t
  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);
      bool ok = true;
      int sum_c0 = 0;
      int sum_c1 = 0;
      for (int i : rep(26)) {
        int c1 = b[i] % qb;
        if (b[i] < (qb + 1) * c1) {
          ok = false;
          break;
        }
        int c0 = (b[i] - (qb + 1) * c1) / qb;
        if (a[i] < qa * c0 + (qa + 1) * c1) {
          ok = false;
          break;
        }
        sum_c0 += c0;
        sum_c1 += c1;
      }
      if (!ok) {
        continue;
      }
      if (r < sum_c1) {
        continue;
      }
      int d = r - sum_c1;
      if (d % qb) {
        continue;
      }
      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);
#undef int
}

}  // 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;

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

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

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

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

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'