Problem p02571 (C++) — buggy submission, verdict: Runtime Error


#include <bits/stdc++.h>
using namespace std;

// #include <string>

#define tenp3 1000
#define tenp5 100000
#define tenp6 1000000
#define tenp9 1000000000
#define infinity 100000000000000000
#define mod 1000000007

typedef long long ll;
typedef vector<long long int> vll;
typedef vector<int> vi;
typedef pair<long long int, long long int> pll;
typedef pair<int, int> pi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef priority_queue<long long int> pqll;
typedef vector<pair<long long int, long long int>> vpll;
typedef vector<pair<int, int>> vpii;

// datatypes

// calc
#define isOdd(x) (x) % 2 == 1
#define isEven(x) (x) % 2 == 0
// #define mat

#define pushb push_back
#define popb pop_back
#define F first
#define S second
#define mp make_pair

#define repe(i, a, b)                                                          \\
  for (long long int i = (long long int)(a); i < (long long int)(b); i++)
#define repi(i, a, b)                                                          \\
  for (long long int i = (long long int)(a); i <= (long long int)(b); i++)
#define repv(x, y) for (auto x : y)
#define repit(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define justSort(x) sort(x.begin(), x.end())
#define justSortR(x) sort(x.rbegin(), x.rend())
#define vec(typeOfVec, nameOfVec, sizeOfVec)                                   \\
  vector<typeOfVec> nameOfVec(sizeOfVec);                                      \\
  for (long long int i = 0; i < sizeOfVec; i++) {                              \\
    cin >> nameOfVec[i];                                                       \\
  }
#define print(x) cout << (x) << "\\n";

#define lb(x, y) lower_bound(x.begin(), x.end(), (y))
#define ub(x, y) upper_bound(x.begin(), x.end(), (y))
#define bs(x, y) binary_search(x.begin(), x.end(), (y))
#define rev(x) reverse(x.begin(), x.end())
#define copy(x, y) copy(x.begin(), x.end(), back_inserter(y));

// matices
#define mat(nameOfMat, typeOFMat, rows, cols, intitialValue)                   \\
  vector<vector<typeOFMat>> nameOfMat(rows,                                    \\
                                      vector<typeOFMat>(cols, intitialValue));
#define gmat(nameOfMat, typeOFMat, rows, cols)                                 \\
  vector<vector<typeOFMat>> nameOfMat(rows, vector<typeOFMat>(cols, 0));       \\
  for (long long int i = 0; i < rows; i++) {                                   \\
    for (long long int j = 0; j < cols; j++) {                                 \\
      cin >> nameOfMat[i][j];                                                  \\
    }                                                                          \\
  }
#define pmat(nameOfMat)                                                        \\
  for (long long int i = 0; i < nameOfMat.size(); i++) {                       \\
    for (long long int j = 0; j < nameOfMat[0].size(); j++) {                  \\
      cout << nameOfMat[i][j] << " ";                                          \\
    }                                                                          \\
    cout << "\\n";                                                              \\
  }                                                                            \\
  cout << "\\n";

//
#define preSum(fromArray, newArray, dataType)                                  \\
  vector<dataType> newArray(fromArray.size() + 1);                             \\
  newArray[0] = 0;                                                             \\
  for (long long int qw = 0; qw < fromArray.size(); qw++) {                    \\
    newArray[qw + 1] = newArray[qw] + fromArray[qw];                           \\
  }

int solve(int tn) {

  string s, t;
  cin >> s >> t;
  ll ans = t.length();
  repi(i, 0, (s.length() - t.length())) {
    ll cunt = 0;
    repe(j, 0, t.length()) {
      if (t[j] != s[i + j]) {
        cunt++;
      }
    }
    ans = min(ans, cunt);
  }
  cout << ans << "\\n";
  return 0;
}

int main() {
  ll t = 1;
  // cin >> t;
  repe(w, 1, t + 1) { solve(w); }
  return 0;
}


Error: 0

Fixed submission:

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

// #include <string>

#define tenp3 1000
#define tenp5 100000
#define tenp6 1000000
#define tenp9 1000000000
#define infinity 100000000000000000
#define mod 1000000007

typedef long long ll;
typedef vector<long long int> vll;
typedef vector<int> vi;
typedef pair<long long int, long long int> pll;
typedef pair<int, int> pi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef priority_queue<long long int> pqll;
typedef vector<pair<long long int, long long int>> vpll;
typedef vector<pair<int, int>> vpii;

// mics
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_seti;
typedef tree<ll, null_type, less<long long int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_setll;

// datatypes

// calc
#define isOdd(x) (x) % 2 == 1
#define isEven(x) (x) % 2 == 0
// #define mat

#define pushb push_back
#define popb pop_back
#define F first
#define S second
#define mp make_pair

#define repe(i, b) for (long long int i = 0; i < (b); i++)
#define repe(i, a, b) for (long long int i = (a); i < (b); i++)

#define repi(i, a, b) for (long long int i = (a); i <= (b); i++)
#define repv(x, y) for (auto x : y)
#define repit(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define justSort(x) sort(x.begin(), x.end())
#define justSortR(x) sort(x.rbegin(), x.rend())
#define vec(typeOfVec, nameOfVec, sizeOfVec)                                   \\
  vector<typeOfVec> nameOfVec(sizeOfVec);                                      \\
  for (long long int i = 0; i < sizeOfVec; i++) {                              \\
    cin >> nameOfVec[i];                                                       \\
  }
#define print(x) cout << (x) << "\\n";

#define lb(x, y) lower_bound(x.begin(), x.end(), (y))
#define ub(x, y) upper_bound(x.begin(), x.end(), (y))
#define bs(x, y) binary_search(x.begin(), x.end(), (y))
#define rev(x) reverse(x.begin(), x.end())
#define copy(x, y) copy(x.begin(), x.end(), back_inserter(y));

// matices
#define mat(nameOfMat, typeOFMat, rows, cols, intitialValue)                   \\
  vector<vector<typeOFMat>> nameOfMat(rows,                                    \\
                                      vector<typeOFMat>(cols, intitialValue));
#define gmat(nameOfMat, typeOFMat, rows, cols)                                 \\
  vector<vector<typeOFMat>> nameOfMat(rows, vector<typeOFMat>(cols, 0));       \\
  for (long long int i = 0; i < rows; i++) {                                   \\
    for (long long int j = 0; j < cols; j++) {                                 \\
      cin >> nameOfMat[i][j];                                                  \\
    }                                                                          \\
  }
#define pmat(nameOfMat)                                                        \\
  for (long long int i = 0; i < nameOfMat.size(); i++) {                       \\
    for (long long int j = 0; j < nameOfMat[0].size(); j++) {                  \\
      cout << nameOfMat[i][j] << " ";                                          \\
    }                                                                          \\
    cout << "\\n";                                                              \\
  }                                                                            \\
  cout << "\\n";

//
#define preSum(fromArray, newArray, dataType)                                  \\
  vector<dataType> newArray(fromArray.size() + 1);                             \\
  newArray[0] = 0;                                                             \\
  for (long long int qw = 0; qw < fromArray.size(); qw++) {                    \\
    newArray[qw + 1] = newArray[qw] + fromArray[qw];                           \\
  }
// global valriable
vector<bool> prime;
// bool *;
ll *fac;

void SieveOfEratosthenes(int n) {
  // prime = new bool[n+1];
  prime = vector<bool>(n + 1, true);
  // memset(prime, true, sizeof(n+1));

  for (int p = 2; p * p <= n; p++) {
    // If prime[p] is not changed, then it is a prime
    if (prime[p] == true) {

      for (int i = p * p; i <= n; i += p)
        prime[i] = false;
    }
  }

  // // Print all prime numbers
  // for (int p=2; p<=n; p++)
  //    if (prime[p])
  //       cout << p << " ";
}

ll power(ll x, ll y) {
  ll res = 1; // Initialize result

  x = x % mod; // Update x if it is more than or
               // equal to p

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % mod;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % mod;
  }
  return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n) { return power(n, mod - 2); }

// // Returns nCr % p using Fermat's little
// // theorem.
// ll nCr(int n, int r){
//     // Base case
//     if (r == 0)
//         return 1;
//
//     // Fill factorial array so that we
//     // can find all factorial of r, n
//     // and n-r
//
//     return (fac[n] * modInverse(fac[r], mod) % mod *
//         modInverse(fac[n - r], mod) % mod) % mod;
// }

void printx(vll &x) {
  for (auto i = x.begin(); i != x.end(); i++) {
    cout << (*i) << " ";
  }
  cout << "\\n";
}
void printy(vll &x) {
  for (auto i = x.begin(); i != x.end(); i++) {
    cout << (*i) << "\\n";
  }
}
void gline(vc &x) {
  // register char c;
  char c = getchar();
  while (c) {
    x.pushb(c);
  }
}
inline void fastsetup() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

void fastscan(ll &number) {
  // variable to indicate sign of input number
  bool negative = false;
  register int c;

  number = 0;

  // extract current character from buffer
  c = getchar();
  if (c == '-') {
    // number is negative
    negative = true;

    // extract the next character from the buffer
    c = getchar();
  }

  // Keep on extracting characters if they are integers
  // i.e ASCII Value lies from '0'(48) to '9' (57)
  for (; (c > 47 && c < 58); c = getchar())
    number = number * 10 + c - 48;

  // if scanned input has a negative sign, negate the
  // value of the input number
  if (negative)
    number *= -1;
}

int solve(int tn) {
  ll n, m, x, y, z, tp;
  // cin >> n;
  string s, t;
  cin >> s >> t;
  ll ans = t.length();
  repe(i, 0, (s.length() - t.length())) {
    ll cunt = 0;
    repe(j, 0, t.length()) {
      if (t[j] != s[i + j]) {
        cunt++;
      }
    }
    ans = min(ans, cunt);
  }
  cout << ans << "\\n";
}

int main() {
  ll t = 1;
  // cin >> t;
  repe(w, 1, t + 1) { solve(w); }
  return 0;
}