QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#241142#7618. Pattern SearchUNos_maricones#WA 53ms3816kbC++201.0kb2023-11-05 23:32:092023-11-05 23:32:10

Judging History

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

  • [2023-11-05 23:32:10]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:3816kb
  • [2023-11-05 23:32:09]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;

const int A = 26;
const int INF = (int) 1e9;

int solve()
{
	string t, p;
	cin >> t >> p;

	vector< int > ft( A ), fp( A );
	for( char c : t )
		++ft[c-'a'];

	for( char c : p )
		++fp[c-'a'];

	const int n = (int) p.size();

	int ans = 0;
	for( int g = n; g; --g )
	{
		int mn = INF;
		for( int i = 0; i < A; ++ i )
		{
			if( fp[i] )
			{
				const int remainder = fp[i] % g;
				if( remainder == 0 || remainder == g - 1 )
				{
					const int cn = ( fp[i] + g - 1 ) / g;
					const int free = ft[i] - fp[i];

					if( free < 0 ) mn = -1;
					else mn = min( mn, free / cn );
				}
				else
					mn = -1;
			}
		}
		ans = max( ans, 1 + mn );
	}
	return ans;
}

int main()
{
	cin.tie( NULL );
	ios_base::sync_with_stdio( 0 );

	int t;
	cin >> t;
	while( t-- )
		cout << solve() << '\n';
	return 0;
}

詳細信息

Test #1:

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

input:

2
bajkaaall aal
abca cba

output:

2
1

result:

ok 2 number(s): "2 1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

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: 53ms
memory: 3556kb

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 2927th numbers differ - expected: '2', found: '1'