#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3F3F3F3F
const int MXN = 3e5 + 5;
const int mod = 1e9 + 7;
int b1, b2;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int dp[505][505];
int R[505];
int f(int l, int r)
{
if (R[l] >= r) return 1;
if (dp[l][r] != -1) return dp[l][r];
dp[l][r] = inf;
for (int i = l; i <= R[i]; i++)
{
dp[l][r] = min(dp[l][r], f(i + 1, r) + 1);
}
return dp[l][r];
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < 505; i++) for (int j = 0; j < 505; j++) dp[i][j] = -1;
int k, m;
cin >> k >> m;
string t[k];
for (int i = 0; i < k; i++) cin >> t[i];
string s;
cin >> s;
int n = s.length();
s = "#" + s;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < k; j++)
{
for (int l = i; l <= n; l++)
{
if (s[l] != t[j][l - i]) break;
R[i] = max(R[i], l);
}
}
cout << R[i] << ' ';
}
cout << '\n';
for (int i = 0; i < m; i++)
{
int l, r;
cin >> l >> r;
l++;
cout << (f(l, r) == inf ? -1 : f(l, r)) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2116 ms |
559520 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |