ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212037 | #3817. 写字 | xpjqz | 0 | 0ms | 1248kb | C++ | 1020b | 2024-10-13 10:33:11 | 2024-10-13 12:15:45 |
answer
#include <bits/stdc++.h>
using namespace std;
string s,a;
int n,m,maxn=99999;
int pd(int xb,int mb,int cnt){
int maxn1=0,maxn2=0,xb1=-1,xb2=-1;
if(mb==m){
return cnt;
}
for(int i = xb-1;i >=0;i--){
maxn1++;
if(s[i]==a[mb]){
xb1=i;
break;
}
}
for(int i = xb+1;i < n;i++){
maxn2++;
if(s[i]==a[mb]){
xb2=i;
break;
}
}
if(xb1==-1&&xb2!=-1){
return pd(xb2,mb+1,cnt+maxn2);
}else if(xb1!=-1&&xb2==-1){
return pd(xb1,mb+1,cnt+maxn1);
}else if(xb1==-1&&xb2==-1){
return -1;
}else if(maxn1>maxn2){
return pd(xb2,mb+1,cnt+maxn2);
}else{
return pd(xb1,mb+1,cnt+maxn1);
}
}
int main(){
cin >> n >> m;
cin >> s >> a;
bool pd2=false;
for(int i = 0;i < n;i++){
if(s[i]==a[0]){
int q=pd(i,1,1);
//cout << q << endl;
if(q==-1){
// cout << -1 << endl;
continue;
}
pd2=true;
maxn=min(maxn,pd(i,1,1));
}
}
if(pd2==false){
cout << -1 << endl;
return 0;
}
cout << maxn << endl;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1240kb
input:
1 1 v v
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 1248kb
input:
26 300 ywzhvjnpdfqtukimsrbxageloc brsmsrbxbxbxbxagagagegelococololegaxagaxaxbxbrbxbrsrsmikimikikimim...
output:
300
result:
wrong answer 1st numbers differ - expected: '299', found: '300'
Subtask #3:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 1244kb
input:
300 300 hgbfdbgcghedefchdabhgdddahcdedebceffegfbceehceeheggffhhddbecbfdhceeedcaeeebdaddfgccggfdcachg...
output:
1123
result:
wrong answer 1st numbers differ - expected: '3643', found: '1123'