LeetCode-Feedback / LeetCode-Feedback

664 stars 315 forks source link

[BUG] - Missing Test Case #23355

Closed stormsunshine closed 1 month ago

stormsunshine commented 1 month ago

LeetCode Username

stormsunshine

Problem Number, Title, and Link

  1. Check if the Rectangle Corner Is Reachable https://leetcode.com/problems/check-if-the-rectangle-corner-is-reachable/

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

A solution that gets accepted fails on the following test case.

5
4
[[5,6,4],[6,4,2],[2,5,4],[3,5,3]]

Language Used for Code

C++

Code used for Submit/Run operation

class Solution {
public:
  bool canReachCorner(int X, int Y, vector<vector<int>>& circles) {
    int n = circles.size();
    vector<int> fa(n + 2);
    for (int i = 0; i < n + 2; i ++)
      fa[i] = i;
    auto getf = [&] (auto self, int x) -> int {
      return x == fa[x] ? x : fa[x] = self(self, fa[x]);
    };
    auto merg = [&] (int x, int y) -> bool {
      x = getf(getf, x);
      y = getf(getf, y);
      if (x == y)
        return false;
      fa[x] = y;
      return true;
    };

    auto dis = [&] (long long x, long long y, int xx, int yy) -> long long {
      return (x - xx) * (x - xx) + (y - yy) * (y - yy);
    };

    vector<bool> outside(n);
    // for (int i = 0; i < n; i ++) {
    //   long long x1 = circles[i][0];
    //   long long y1 = circles[i][1];
    //   long long r1 = circles[i][2];
    //   if ((x1 > X && dis(x1, y1, X, y1) > r1 * r1) || (y1 > Y && dis(x1, y1, x1, Y) > r1 * r1))
    //     outside[i] = true;
    //   else if ((x1 > X || y1 > Y) && dis(x1, y1, X, Y) > r1 * r1)
    //     outside[i] = true;
    // }

    auto check = [&] (long long x, long long y, long long a, long long b, long long x1, long long y1, long long x2, long long y2) {
      long long c1 = (x1 - x) * b - (y1 - y) * a;
      long long c2 = (x2 - x) * b - (y2 - y) * a;
      return !((c1 > 0 && c2 > 0) || (c1 < 0 && c2 < 0));
    };

    for (int i = 0; i < n; i ++) if (!outside[i]) {
      long long x1 = circles[i][0];
      long long y1 = circles[i][1];
      long long r1 = circles[i][2];
      if ((y1 <= Y && dis(x1, y1, 0, y1) <= r1 * r1) || (x1 <= X && dis(x1, y1, x1, Y) <= r1 * r1))
        merg(i, n);
      if ((y1 <= Y && dis(x1, y1, X, y1) <= r1 * r1) || (x1 <= X && dis(x1, y1, x1, 0) <= r1 * r1))
        merg(i, n + 1);

      for (int j = i + 1; j < n; j ++) if (!outside[j]) {
        long long x2 = circles[j][0];
        long long y2 = circles[j][1];
        int r2 = circles[j][2];
        long long d = dis(x1, y1, x2, y2);
        if (d > 1ll * (r1 + r2) * (r1 + r2))
          continue;

        if ((x1 >= 0 && x1 <= X && y1 >= 0 && y1 <= Y)
        || (x2 >= 0 && x2 <= X && y2 >= 0 && y2 <= Y)) {
          merg(i, j);
          continue;
        }
        long long d1 = x2 - x1, d2 = y2 - y1;
        if (check(0, 0, X, Y, x1, x2, y1, y2)
        && check(x1, y1, d1, d2, 0, 0, X, Y)) {
          merg(i, j);
          continue;
        }
        if (check(0, Y, X, -Y, x1, x2, y1, y2)
        && check(x1, y1, d1, d2, 0, Y, X, 0)) {
          merg(i, j);
          continue;
        }
      }
    }
    return merg(n, n + 1);
  }
};

Expected behavior

Add the missing test case so that the code above won't get accepted when submitted.

Screenshots

No response

Additional context

No response

exalate-issue-sync[bot] commented 1 month ago

Epiphania_Ekenimoh commented: Hello,

Your reported issue has been relayed to our team for thorough investigation. We appreciate your patience as we work to address and resolve this matter. We will reach out to you when we have updates regarding the issue.

If you have any further questions or concerns in the meantime, please feel free to let us know.

Best regards, LeetCode Support Team

exalate-issue-sync[bot] commented 1 month ago

Epiphania_Ekenimoh commented: Thank you for your time.

Your feedback has been used to enhance the problem. As a token of our appreciation, your LeetCode account has been credited with 100 LeetCoins.

If you have any more questions or additional feedback, please don't hesitate to let us know. Your continued support is invaluable to us!

Best regards, The LeetCode Team