답안 #315735

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315735 2020-10-23T20:30:37 Z DanerZein Bajka (COCI20_bajka) C++14
20 / 70
1 ms 384 KB
#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

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++){
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -