QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#243934#1276. String DistancePhantomThreshold#AC ✓705ms18268kbC++201.1kb2023-11-08 19:24:142023-11-08 19:24:14

Judging History

你现在查看的是最新测评结果

  • [2023-11-08 19:24:14]
  • 评测
  • 测评结果:AC
  • 用时:705ms
  • 内存:18268kb
  • [2023-11-08 19:24:14]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
//#define int long long
using namespace std;

void upd(int &a,const int &b){ if(a==-1||a>b)a=b; }
const int maxn = 210000;

int n,m,Q;
string S,T;
int a[maxn],b[maxn];
int nex[maxn][27];

int f[22][22];

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int Tcase; cin>>Tcase;
	while(Tcase--)
	{
		cin>>S>>T;
		n=S.size(),m=T.size();
		S=' '+S,T=' '+T;
		for(int i=1;i<=n;i++) a[i]=S[i]-'a'+1;
		for(int i=1;i<=m;i++) b[i]=T[i]-'a'+1;
		
		for(int c=1;c<=26;c++) nex[n+1][c]=n+1;
		for(int i=n;i>=1;i--)
		{
			for(int j=1;j<=26;j++) nex[i][j]=nex[i+1][j];
			nex[i][a[i]]=i;
		}
		
		cin>>Q;
		while(Q--)
		{
			int l,r; cin>>l>>r;
			memset(f,-1,sizeof f);
			f[0][0]=l-1;
			for(int i=0;i<m;i++)
			{
				for(int j=0;j<=i;j++) if(f[i][j]!=-1 && f[i][j]<=r)
				{
					upd(f[i+1][j],f[i][j]);
					int p=nex[ f[i][j]+1 ][ b[i+1] ];
					upd(f[i+1][j+1],p);
				}
			}
			
			int ans=0;
			for(int j=0;j<=m;j++) if(f[m][j]<=r && f[m][j]!=-1)
				ans=max(ans,j);
			cout<<r-l+1+m-ans*2<<'\n';
		}
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5664kb

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: 705ms
memory: 18268kb

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