-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Don_t_Try_to_Count.cpp
More file actions
44 lines (36 loc) · 861 Bytes
/
A_Don_t_Try_to_Count.cpp
File metadata and controls
44 lines (36 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t; // number of test cases
while (t--)
{
int n, m;
cin >> n >> m;
string x, s;
cin >> x >> s;
string cur = x;
int ops = 0;
bool found = false;
// Cap the maximum length we need to build
int maxLen = m * 2 + n;
// Try until cur is long enough
while ((int)cur.size() <= maxLen)
{
// Check if s is a substring of cur
if (cur.find(s) != string::npos)
{
cout << ops << "\n";
found = true;
break;
}
// Perform operation: double the string
cur += cur;
ops++;
}
if (!found)
cout << -1 << "\n";
}
return 0;
}