Submission #315735

#TimeUsernameProblemLanguageResultExecution timeMemory
315735DanerZeinBajka (COCI20_bajka)C++14
20 / 70
1 ms384 KiB
#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)

bajka.cpp: In function 'int main()':
bajka.cpp:9:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |   for(int i=0;i<x.size();i++){
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...