# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
315735 | DanerZein | Bajka (COCI20_bajka) | C++14 | 1 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
string x,y;
cin>>x>>y;
int id=-1;
for(int i=0;i<x.size();i++){
if(x[i]==y[0]){
id=i;
break;
}
}
if(id==-1) {cout<<"-1\n";
return 0;}
int j=1;
bool sw=0;
int res=0;
while(true){
if(j==m) break;
if(id+1<n && x[id+1]==y[j]){
id++;
j++;
}
else
if(id-1>=0 && x[id-1]==y[j]){
id--;
j++;
}
else{
sw=1;
break;
}
res++;
}
if(sw==1) cout<<"-1\n";
else cout<<res<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |