QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261465#7618. Pattern Searchxianggui#WA 1ms5700kbC++202.4kb2023-11-22 21:59:352023-11-22 21:59:36

Judging History

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

  • [2023-11-22 21:59:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5700kb
  • [2023-11-22 21:59:35]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int T;
char s[2000010],t[2000010];
ll num[30],tnum[30],snum[30];
int main()
{
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout.tie(0);
    cin>>T;
    while(T--)
    {
        cin>>s>>t;
        int ls=strlen(s);
        int lt=strlen(t);
        for(int i=0;i<26;i++) num[i]=tnum[i]=snum[i]=0;
        for(int i=0;i<ls;i++) snum[s[i]-'a']++;
        for(int i=0;i<lt;i++)
        {
            num[t[i]-'a']++;
        }
        ll minn=1e18;
        for(int i=0;i<26;i++)
        {
            if(!num[i]) continue;
            minn=min(minn, num[i]);
        }
        bool flag=0;
        for(int i=0;i<26;i++)
        {
            if(!num[i]) continue;
            if(num[i]!=1)
            {
                flag=1;
                break;
            }
        }
        if(!flag)
        {
            ll ans=1e18;
            for(int i=0;i<26;i++)
            {
                if(!num[i]) continue;
                ans=min(ans,snum[i]/num[i]);
            }
            cout<<ans<<'\n';
            continue;
        }
        flag=0;
        for(int i=0;i<26;i++)
        {
            if(!num[i]) continue;
            if(num[i]%minn)
            {
                flag=1;
                break;
            }
        }
        ll len=0;
        if(minn==1||flag)
        {
            ll ans=1e18;
            for(int i=0;i<26;i++)
            {
                if(!num[i]) continue;
                ll tem=num[i]/2;
                if(snum[i]<tem)
                {
                    ans=0;
                    break;
                }
                snum[i]-=tem;
                num[i]-=tem;
                ans=min(ans, snum[i]/num[i]);
            }
            cout<<ans<<'\n';
        }
        else
        {
            ll ans=1e18;
            for(int i=0;i<26;i++)
            {
                if(!num[i]) continue;
                ll tem=num[i]/minn*(minn-1);
                if(snum[i]<tem)
                {
                    ans=0;
                    break;
                }
                snum[i]-=tem;
                num[i]-=tem;
                ans=min(ans,snum[i]/num[i]);
            }
            cout<<ans<<'\n';
        }
    }
    return 0;
}
/*
2
bajkaaall aal
abca cba

1
aaaabbbbcccc cbacbaba

*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5700kb

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

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'