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

#include <bits/stdc++.h>
using namespace std;
//
typedef long double ld;
typedef long long int ll;
//
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define prq priority_queue<ll>;
#define vbs(xx, x) binary_search(all(xx), x)
#define vlb(xx, x) lower_bound(all(xx), x)
#define vub(xx, x) upper_bound(all(xx), x)
//
ll MOD = 998244353;
ll M = 1e9 + 7;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008
//
#define forx(i, j, n) for (long long int i = j; i < n; i++)
#define fory(i, j, n) for (long long int i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fs first
#define sn second
#define mem(x, y) memset(x, y, sizeof(x))
//
#define nl "\\n"
#define flush fflush(stdout)
clock_t tim;
void showtime() {
  tim = clock() - tim;
  cout << " ===> " << (ld)tim / CLOCKS_PER_SEC << " seconds\\n";
}
//
ll mul(ll mul_1, ll mul_2) {
  ll mul_t = ((mul_1 % MOD) * (mul_2 % MOD) + MOD) % MOD;
  return mul_t;
}
ll mul3(ll mul_1, ll mul_2, ll mul_3) {
  ll mul_t = mul(mul(mul_1, mul_2), mul_3) % MOD;
  return mul_t;
}
ll add(ll add_1, ll add_2) {
  ll add_t = ((add_1 % MOD) + (add_2 % MOD) + MOD + MOD) % MOD;
  return add_t;
}
ll sub(ll sub_1, ll sub_2) {
  ll sub_r = 1e15;
  ll sub_t = (((sub_1 + sub_r) % MOD) - ((sub_2 + sub_r) % MOD) + sub_r) % MOD;
  return sub_t;
}
ll pwm(ll x, ll y, ll p = M) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y / 2;
    x = (x * x) % p;
  }
  return res;
}
ll pw(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y / 2;
    x = (x * x);
  }
  return res;
}
ll modinv(ll n) { return pwm(n, M - 2, M); }
ll gcd(ll num1, ll num2) { return (num2 ? gcd(num2, num1 % num2) : num1); }
ll lcm(ll num1, ll num2) { return 1LL * ((num1 * num2) / __gcd(num1, num2)); }
ll myceil(ll x, ll y) { return (x + y - 1) / y; }
ll my_log(ll n, ll b) {
  ll i = 1;
  ll ans = 0;
  while (1) {
    if (i > n) {
      ans--;
      break;
    }
    if (i == n)
      break;
    i *= b;
    ans++;
  }
  return ans;
}
//
// ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
// ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
// ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
// ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
// bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
// ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
// ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }
// //
// ll prime[1000005];
// ll maxn=1e9+7;
// void sieve(){ forx(i,0,1000005) prime[i]=i; for(ll p=2; 1LL*p*p<maxn; p++){
// if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i)
// prime[i]=p; } } return; } bool isPrime(ll pri){if(pri==1||pri==0) return
// 0;if(prime[pri]==pri) return 1;return 0;} bool IsPrime(ll number){if
// (((!(number & 1)) && number != 2) || (number < 2) || (number % 3 == 0 &&
// number != 3)) return false;for (ll k = 1; 36 * k * k - 12 * k < number; ++k)
// if ((number % (6 * k + 1) == 0) || (number % (6 * k - 1) == 0)) return
// false;return true;} vl alldiv(ll num){vl prDiv; for(ll i=1; 1LL*i*i<=num;
// i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); }
// }sort(all(prDiv)); return prDiv;} vl prdiv(ll num){vl prDiv; while(num!=1){
// prDiv.pb(prime[num]); ll prtemp=prime[num];  num/=prtemp; }return prDiv;}
// //
// bool ispalin(string d){ll n=d.length();for(ll
// i=0;i<n/2;i++){if(d[i]!=d[n-i-1]) return 0;}return 1;}
// //
// const int MAX=2*100005;
//
// bool vis[MAX];
// vvi adj(MAX);
// ll dep[MAX];
// ll ht[MAX];
// vl diff;
// void dfs(int s,int p){
//     vis[s]=true;
//     if(p!=-1) ht[s]=ht[p]+1;
//     for(auto i:adj[s]){
//         if(!vis[i]) {
//             dfs(i,s);
//             dep[s]+=1+dep[i];
//         }
//     }
//     diff.pb(dep[s]-ht[s]);
// }
// ll sos(ll a,ll b,ll c){
//     return (a-b)*(a-b)+(b-c)*(b-c)+(c-a)*(c-a);
// }

void solve() {
  ll n, j = 0, k, m, f = 0, p, q;
  string s, t;
  cin >> s >> t;
  n = s.length();
  k = t.length();
  forx(i, 0, n) {
    if (s[i] != t[i])
      f++;
  }
  cout << f << "\\n";
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll x = 1;
  forx(u, 0, x) {
    // cout<<"Case #"<<h+1<<":"<<" ";
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
//
typedef long double ld;
typedef long long int ll;
//
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define prq priority_queue<ll>;
#define vbs(xx, x) binary_search(all(xx), x)
#define vlb(xx, x) lower_bound(all(xx), x)
#define vub(xx, x) upper_bound(all(xx), x)
//
ll MOD = 998244353;
ll M = 1e9 + 7;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008
//
#define forx(i, j, n) for (long long int i = j; i < n; i++)
#define fory(i, j, n) for (long long int i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define fs first
#define sn second
#define mem(x, y) memset(x, y, sizeof(x))
//
#define nl "\\n"
#define flush fflush(stdout)
clock_t tim;
void showtime() {
  tim = clock() - tim;
  cout << " ===> " << (ld)tim / CLOCKS_PER_SEC << " seconds\\n";
}
//
ll mul(ll mul_1, ll mul_2) {
  ll mul_t = ((mul_1 % MOD) * (mul_2 % MOD) + MOD) % MOD;
  return mul_t;
}
ll mul3(ll mul_1, ll mul_2, ll mul_3) {
  ll mul_t = mul(mul(mul_1, mul_2), mul_3) % MOD;
  return mul_t;
}
ll add(ll add_1, ll add_2) {
  ll add_t = ((add_1 % MOD) + (add_2 % MOD) + MOD + MOD) % MOD;
  return add_t;
}
ll sub(ll sub_1, ll sub_2) {
  ll sub_r = 1e15;
  ll sub_t = (((sub_1 + sub_r) % MOD) - ((sub_2 + sub_r) % MOD) + sub_r) % MOD;
  return sub_t;
}
ll pwm(ll x, ll y, ll p = M) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y / 2;
    x = (x * x) % p;
  }
  return res;
}
ll pw(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x);
    y = y / 2;
    x = (x * x);
  }
  return res;
}
ll modinv(ll n) { return pwm(n, M - 2, M); }
ll gcd(ll num1, ll num2) { return (num2 ? gcd(num2, num1 % num2) : num1); }
ll lcm(ll num1, ll num2) { return 1LL * ((num1 * num2) / __gcd(num1, num2)); }
ll myceil(ll x, ll y) { return (x + y - 1) / y; }
ll my_log(ll n, ll b) {
  ll i = 1;
  ll ans = 0;
  while (1) {
    if (i > n) {
      ans--;
      break;
    }
    if (i == n)
      break;
    i *= b;
    ans++;
  }
  return ans;
}
//
// ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
// ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
// ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
// ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
// bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
// ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
// ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }
// //
// ll prime[1000005];
// ll maxn=1e9+7;
// void sieve(){ forx(i,0,1000005) prime[i]=i; for(ll p=2; 1LL*p*p<maxn; p++){
// if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i)
// prime[i]=p; } } return; } bool isPrime(ll pri){if(pri==1||pri==0) return
// 0;if(prime[pri]==pri) return 1;return 0;} bool IsPrime(ll number){if
// (((!(number & 1)) && number != 2) || (number < 2) || (number % 3 == 0 &&
// number != 3)) return false;for (ll k = 1; 36 * k * k - 12 * k < number; ++k)
// if ((number % (6 * k + 1) == 0) || (number % (6 * k - 1) == 0)) return
// false;return true;} vl alldiv(ll num){vl prDiv; for(ll i=1; 1LL*i*i<=num;
// i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); }
// }sort(all(prDiv)); return prDiv;} vl prdiv(ll num){vl prDiv; while(num!=1){
// prDiv.pb(prime[num]); ll prtemp=prime[num];  num/=prtemp; }return prDiv;}
// //
// bool ispalin(string d){ll n=d.length();for(ll
// i=0;i<n/2;i++){if(d[i]!=d[n-i-1]) return 0;}return 1;}
// //
// const int MAX=2*100005;
//
// bool vis[MAX];
// vvi adj(MAX);
// ll dep[MAX];
// ll ht[MAX];
// vl diff;
// void dfs(int s,int p){
//     vis[s]=true;
//     if(p!=-1) ht[s]=ht[p]+1;
//     for(auto i:adj[s]){
//         if(!vis[i]) {
//             dfs(i,s);
//             dep[s]+=1+dep[i];
//         }
//     }
//     diff.pb(dep[s]-ht[s]);
// }
// ll sos(ll a,ll b,ll c){
//     return (a-b)*(a-b)+(b-c)*(b-c)+(c-a)*(c-a);
// }

void solve() {
  long long int n, j = 0, k, m, f = 0, p, q;
  string s, t;
  cin >> s >> t;
  n = s.length();
  m = t.length();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (s[i - 1] == t[j - 1]) { // for length of longest repeating subsequence
                                  // use extra condition of i!=j
        dp[i][j] = dp[i - 1][j - 1] + 1;
      } else
        dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
    }
  }
  cout << n - dp[n][n] << "\\n";
}

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll x = 1;
  forx(u, 0, x) {
    // cout<<"Case #"<<h+1<<":"<<" ";
    solve();
  }
  return 0;
}