# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1045554 |
2024-08-06T05:38:33 Z |
javotaz |
Dabbeh (INOI20_dabbeh) |
C++17 |
|
369 ms |
53072 KB |
// In the Name of Allah
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,avx,avx2,sse4.2,popcnt,tune=native")
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
const int N = 3e5 + 7, M = 1e4 + 7, K = 5e5 + 7;
string s, a[M];
int n, q, dp[N], c, t[K][26];
void add(int id) {
int p = 0;
for (int i = 0; i < a[id].size(); i++) {
if (!t[p][a[id][i] - 'a'])
t[p][a[id][i] - 'a'] = ++c;
p = t[p][a[id][i] - 'a'];
}
}
void ip() {
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
add(i);
}
cin >> s;
}
void solve() {
while (q--) {
int l, r;
cin >> l >> r;
fill(dp + l, dp + r + 1, 0);
for (int i = r - 1; i >= l; --i) {
dp[i] = n + 1;
for (int j = i, p = 0; j < r && (p = t[p][s[j] - 'a']); j++)
dp[i] = min(dp[i], 1 + dp[j + 1]);
}
cout << ((dp[l] > n)? -1 : dp[l]) << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ip(), solve();
return 0;
}
Compilation message
Main.cpp: In function 'void add(int)':
Main.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int i = 0; i < a[id].size(); i++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
120 ms |
42320 KB |
Output is correct |
3 |
Correct |
183 ms |
31568 KB |
Output is correct |
4 |
Correct |
256 ms |
41552 KB |
Output is correct |
5 |
Correct |
278 ms |
38076 KB |
Output is correct |
6 |
Correct |
369 ms |
47888 KB |
Output is correct |
7 |
Incorrect |
232 ms |
53072 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
19384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
120 ms |
42320 KB |
Output is correct |
3 |
Correct |
183 ms |
31568 KB |
Output is correct |
4 |
Correct |
256 ms |
41552 KB |
Output is correct |
5 |
Correct |
278 ms |
38076 KB |
Output is correct |
6 |
Correct |
369 ms |
47888 KB |
Output is correct |
7 |
Incorrect |
232 ms |
53072 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |