# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
705774 |
2023-03-05T08:06:16 Z |
Abito |
Bajka (COCI20_bajka) |
C++14 |
|
1 ms |
212 KB |
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define rip(i,a,b) for(ll i=a;i<=b;i++)
#define in insert
using namespace std;
const ll M=998244353;
int32_t main(){
//ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n,m;
cin>>n>>m;
string s1,s2;
cin>>s1>>s2;
s1='!'+s1;
s2='!'+s2;
int idx=0;
for(int i=1;i<=n;i++){
if(s1[i]==s2[1]) idx=i;
}
if(idx==0){
cout<<-1;
return 0;
}
int ans=0;
for(int i=2;i<=m;i++){
bool c=0;
for(int j=1;j<=n;j++){
if(s1[j]==s2[i]){ans+=abs(j-idx);idx=j;c=1;}
}
if(!c){
cout<<-1;
return 0;
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |