QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281668#7618. Pattern SearchSaya_AlterWA 1ms5668kbC++141.2kb2023-12-10 15:21:332023-12-10 15:21:33

Judging History

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

  • [2023-12-10 15:21:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5668kb
  • [2023-12-10 15:21:33]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 10;

char s[N], t[N];

int cnt[30], c[30];

void solve() {
    memset(cnt, 0, sizeof(cnt));
    memset(c, 0, sizeof(c));
    cin >> s >> t;
    for (int i = 0; s[i]; i++) cnt[s[i] - 'a']++;
    for (int i = 0; t[i]; i++) c[t[i] - 'a']++;
    int ans = 1;
    for (int i = 0; i < 26; i++) {
        cnt[i] -= c[i];
        if (cnt[i] < 0) ans--;
    }
    if (ans <= 0) {
        cout << ans << "\n";
        return ;
    }
    for (int k = 1; ; k++) {
        bool flag = true, pd = true; 
        for (int i = 0; i < 26; i++) {
            if (k > c[i] + 1) flag = false;
            int s = (c[i] + k - 1) / k;
            if (s * (k - 1) > c[i]) pd = false;
        }
        if (!flag) break;
        if (pd) {
            int Min = 0x3f3f3f3f;
            for (int i = 0; i < 26; i++) if (c[i]) {
                Min = min(Min, cnt[i] / ((c[i] + k - 1) / k));
            }
            if (Min != 0x3f3f3f3f) ans = max(ans, 1 + Min);
        }
    }
    cout << ans << "\n";
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
    int T = 1; cin >> T;
    while (T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5440kb

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
-1
1

result:

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