QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#223169#7618. Pattern Searchucup-team1631#WA 0ms3636kbC++231.7kb2023-10-21 22:11:242023-10-21 22:11:24

Judging History

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

  • [2023-10-21 22:11:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2023-10-21 22:11:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? (a = b, 1) : 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int z;
    cin >> z;
    while (z--) {
        string s, t;
        cin >> s >> t;
        vector<ll> cnts(26), cntt(26);
        for (char c : s) {
            ++cnts[c - 'a'];
        }
        for (char c : t) {
            ++cntt[c - 'a'];
        }
        int g = 0;
        rep(c, 0, 26) { g = gcd(g, cntt[c]); }
        if (g == 1) {
            ll lb = 0, ub = 1e9;
            while (ub - lb > 1) {
                int m = (lb + ub) / 2;

                bool ok = true;
                rep(c, 0, 26) {
                    ll tt = (cntt[c] / 2) * (m + 1) + (cntt[c] % 2) * m;
                    if (cnts[c] < tt) {
                        ok = false;
                        break;
                    }
                }
                if (ok)
                    lb = m;
                else
                    ub = m;
            }
            cout << lb << "\n";
        } else {
            ll maxA = 1e9;
            rep(c, 0, 26) {
                if (cntt[c] != 0) {
                    chmin(maxA, cnts[c] / (cntt[c] / g));
                }
            }
            cout << max(0LL, maxA - g + 1) << "\n";
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

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

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'