#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);
cout << "3 13\nab\nac\naef\nabaaceaef\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\n1 2\n6 9\n5 9\n4 9";
return 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);
}
}
}
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 |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |