# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001572 | vjudge1 | Dabbeh (INOI20_dabbeh) | C++17 | 57 ms | 7688 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define oo 1e9
const int MAX = 1e4 + 5;
int n, q;
string s;
string t[MAX];
int to[MAX][27][26];
void solve(){
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> t[i];
t[i] = '{' + t[i];
}
cin >> s;
s = '{' + s;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= t[i].size() - 1; j++){
to[j - 1][t[i][j - 1] - 'a'][t[i][j] - 'a'] = 1;
// cout << j - 1 << ' ' << t[i][j - 1] - 'a' << ' ' << t[i][j] - 'a' << '\n';
}
}
while(q--){
int l, r; cin >> l >> r;
l++;
int ans = 1;
int i = 0, c = 26;
while(true){
if(l == r + 1) break;
if(to[i][c][s[l] - 'a']){
c = s[l] - 'a';
i++;
l++;
}
else if(!to[0][26][s[l] - 'a']){
ans = -1;
break;
}
else{
ans++;
i = 0, c = 26;
}
}
cout << ans << '\n';
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while(t--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |