QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#811682 | #1276. String Distance | HappyNewDay | AC ✓ | 1113ms | 193104kb | C++14 | 1.3kb | 2024-12-12 22:59:43 | 2024-12-12 22:59:44 |
Judging History
answer
#include <bits/stdc++.h>
#define Fst first
#define Snd second
#define MP make_pair
#define ll long long
#define PII pair<int,int>
#define PIL pair<int,ll>
#define PLI pair<ll,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
using namespace std;
int tac,n,m,q;
char str[100010];
string sA,sB;
int d[100010][22][22];
inline void Main()
{
scanf("%s",str),sA=str,n=sA.size();
scanf("%s",str),sB=str,m=sB.size();
for (int i=0;i<n;i++)
for (int j=0;j<=m;j++)
for (int k=0;k<=m;k++) d[i][j][k]=-1e9;
for (int i=0;i<n;i++)
{
for (int j=0;j<=m;j++)
{
if (j<m && sA[i]==sB[j]) d[i][j+1][1]=i;
if (i==n-1) continue;
for (int k=0;k<=m;k++)
{
if (j<m) d[i][j+1][k]=max(d[i][j+1][k],d[i][j][k]);
d[i+1][j][k]=max(d[i+1][j][k],d[i][j][k]);
if (j<m && sA[i+1]==sB[j]) d[i+1][j+1][k+1]=max(d[i+1][j+1][k+1],d[i][j][k]);
}
}
}
scanf("%d",&q);
while (q--)
{
int l,r; scanf("%d%d",&l,&r),l--,r--; int res=0;
for (int i=0;i<=m;i++)
for (int j=0;j<=m;j++) if (d[r][i][j]>=l) res=max(res,j);
printf("%d\n",r-l+1-res+m-res);
}
}
int main()
{
scanf("%d",&tac);
while (tac--) Main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3892kb
input:
1 qaqaqwqaqaq qaqwqaq 3 1 7 2 8 3 9
output:
4 2 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1113ms
memory: 193104kb
input:
10 rtedxofnuatdpogdzftepqhlwiavwisshpvlcwdkzlccofacdisafkpzmppgdwahposjlgqxqdupksokprgaymznbtyuenyikazrmjonfqawzcmuaqowrizdortxplnogmntadqqpwgolfcyqswtncqldgkrmgbovkyaxsuqwzftujheouhiynkjbzdnnhmreheoawkkljxmiwghewmqvjvmywukckjzwvfnjomthjkvijujdksawjmfrrgmhvpqazesdmeyjvougzmhlxrqmdyripgomcrawinxmfiyr...
output:
21 22 23 24 25 26 27 28 29 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 61 62 63 64 65 64 65 66 67 68 69 70 71 72 73 74 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 92 93 94 95 96 95 96 97 98 99 100 101 102 103 102 1...
result:
ok 995160 lines