QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224953#7618. Pattern Searchnocriz#WA 29ms5808kbC++201.8kb2023-10-23 18:20:042023-10-23 18:20:04

Judging History

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

  • [2023-10-23 18:20:04]
  • 评测
  • 测评结果:WA
  • 用时:29ms
  • 内存:5808kb
  • [2023-10-23 18:20:04]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef LOCAL
#include "cp_debug.h"
#else
#define debug(...) 42
#endif
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
template<typename T, typename... Args> void read(T &first, Args& ... args) {
    read(first);
    read(args...);
}
template<typename T> void write(T x) {
    if(x > 9) write(x/10);
    putchar(x%10 + '0');
}

const int MAXN = 2100000;
char s[MAXN], t[MAXN];

void solve() {
    scanf("%s%s", s, t);
    int ns = strlen(s), nt = strlen(t);
    vector<int> cnts(26, 0), cntt(26, 0);
    rep(i,0,ns) cnts[s[i]-'a']++;
    rep(i,0,nt) cntt[t[i]-'a']++;
    int ans = 0, minch = 1e9, initct = 1e9;
    rep(i,0,26) if(cntt[i] > 0) {
        minch = min(minch, cntt[i]);
        initct = min(initct, cnts[i]/cntt[i]);
    }
    ans = initct;
    debug(ans);
    for(int nprd = 1; nprd <= minch; ++nprd) {
        int ct = 1e9;
        rep(i,0,26) if(cntt[i]) {
            int prd = (cntt[i]+nprd) / (nprd+1);
            debug(cntt[i],prd,nprd);
            debug(nprd,i,prd);
            int ff;
            if(cnts[i] < cntt[i]) {
                ff = 0;
            } else {
                ff = 1 + (cnts[i]-cntt[i])/prd;
            }
            ct = min(ct, ff);
        }
        ans = max(ans, ct);
    }
    cout << ans << '\n';
}

signed main() {
    int T; read(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: 5692kb

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5808kb

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
1

result:

ok 16 numbers

Test #3:

score: -100
Wrong Answer
time: 29ms
memory: 5808kb

input:

90522
cyykzyylklyll ylcyllklzk
ttusuuudtdtqus uuddu
uefyqfkiblyfkyd ffyyqde
qfxqecljeqeedea jqdxf
prrbfxdxffpbpp ffppd
ynjgygygjnjnjg jgynjggn
maenpaksmxyya saxkep
nrdnbnjipnjowjz djbwojzrpni
oputuoufoojupu uoouopo
mphmhphpkpkpmhp phmhpppp
zwznzpzqyjczzy wczjnpzqy
pfxfxxkfffpfx fxffkffxpx
hzdhzhhh h...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
1
1
1
2
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
2
3
1
1
1
1
1
1
1
1
1
2
2
1
1
1
1
1
2
1
1
1
1
4
1
2
1
1
1
1
1
3
1
1
3
1
1
1
1
1
1
1
1
1
1
1
3
1
1
4
1
1
1
1
1
1
1
1
1
1
5
1
7
1
1
1
1
1
3
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
...

result:

wrong answer 5721st numbers differ - expected: '1', found: '2'