-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
58 lines (51 loc) · 1.49 KB
/
D.cpp
File metadata and controls
58 lines (51 loc) · 1.49 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
int xxxx[]={-1,0,1,0,-1,1,1,-1};
int yyyy[]={0,1,0,-1,-1,1,-1,1};
void solve(){
string str; cin >> str;
int N; cin >> N;
string strs[N]; for (auto &a : strs) cin >> a;
vector<tuple<int,int,int>> v;
int s = str.size();
int e = 0;
for (int i = 0; i < str.size(); i++) {
for (int k = 0; k < N; k++) {
string x = strs[k];
bool yes = true;
for (int j = 0; j < x.size(); j++) {
yes &= str[i + j] == x[j];
}
if (yes) {
if (e < i + x.size() && i <= e) {
while (v.size() >= 2 && get<2>(v[v.size() - 2]) >= i) v.pop_back();
while (v.size() && get<1>(v.back()) == i) v.pop_back();
v.push_back({k, i, i+x.size()});
s = min(s, i);
e = max(e, i + (int) x.size());
}
}
}
}
if (s == 0 && e == str.size()) {
cout << v.size() << '\n';
for (auto [a,b,e] : v) {
cout << a+1 << ' ' << b+1 << '\n';
}
} else cout << -1 << '\n';
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T=1;
cin >>T;
while (T--) {
solve();
}
return 0;
}