WA in simple operations

can anyone tell me case i am missing

struct node {
  int len = 0;
  int k = 0;
  int id ;
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("a.txt", "w", stdout);
#endif
  int t;
  cin >> t;
  while (t--) {
    string s, t;
    cin >> s >> t;
    int n = s.length();

    int fir = -1, last = 0 ;
    if (s == t) {
      cout << 0 << "\n";
      continue;
    }
    forr(i, n) {
      if (fir == -1 && s[i] != t[i])
        fir = i;
      if (s[i] != t[i])
        last =  i;
    }
    node a[last - fir + 1][2];
    a[0][0].len = a[0][1].len = 1;
    a[0][0].k = a[0][1].k = 1;
    a[0][0].id = a[0][1].id = fir;
    int j = 1;
    int als = 0;
    for (int i = fir + 1; i <= last; i++) {
      if (s[i] != t[i]) {
        int tmp1, tmp2;
        tmp1 = (a[j - 1][0].len + 1) * (a[j - 1][0].k + 1);
        tmp2 = (a[j - 1][1].len + 1) * (a[j - 1][1].k + 1);
        if (tmp1 < tmp2) {
          a[j][0].len = a[j - 1][0].len + 1;
          a[j][0].k = a[j - 1][0].k + 1;
          a[j][0].id = i;
        } else {
          a[j][0].len = a[j - 1][1].len + 1;
          a[j][0].k = a[j - 1][1].k + 1;
          a[j][0].id = i;
        }
      
        tmp1 = 0, tmp2 = 0;
        tmp1 = (a[j - 1][0].len + (i - a[j - 1][0].id )) * (a[j - 1][0].k);
        tmp2 = (a[j - 1][1].len + (i - a[j - 1][1].id )) * (a[j - 1][1].k);
        if (tmp1 < tmp2) {
          a[j][1].len = a[j - 1][0].len + (i - a[j - 1][0].id );
          a[j][1].k = a[j - 1][0].k;
          a[j][1].id = i;
        } else {
          a[j][1].len = a[j - 1][1].len + (i - a[j - 1][1].id );
          a[j][1].k = a[j - 1][1].k;
          a[j][1].id = i;
        }
       
        als = j;
        j++;
      }
    }

    int ans  = min(a[als][0].len * a[als][0].k, a[als][1].len * a[als][1].k);
    cout << ans << "\n";
  }
  return 0;
}
3 Likes

what is your logic?

2 Likes

whenever s[i]!=t[i] i am storing that if i make this indx is seperated from prev ones or should i consider this index with then at a[ind][0] it is storing the min value i get till that ind if this index is conidered seperate at a[ind][1] minimum value if it got taken with them

4 Likes