<commit_before>public class Solution
{
  private int N, M;
  private int[][] dungeon;
  private int[][] health;

  public int calculateMinimumHP (int[][] dungeon)
  {
    this.dungeon = dungeon;
    if (dungeon == null)
      throw new IllegalArgumentException();
    N = dungeon.length;
    if (N == 0)
      throw new IllegalArgumentException();
    M = dungeon[0].length;
    if (M == 0)
      throw new IllegalArgumentException();
    health = new int[N][M];
    int lower = 0, upper = Integer.MAX_VALUE;
    while (upper - lower > 1)
    {
      int mid = (lower + upper - 1) / 2;
      if (success(mid))
        upper = mid + 1;
      else
        lower = mid + 1;
    }
    return lower + 1;
  }

  private boolean success (int iniHealth)
  {
    health[0][0] = dungeon[0][0] + iniHealth;
    if (health[0][0] < 0)
      return false;
    for (int j = 1; j < M; ++j)
      health[0][j] = health[0][j - 1] >= 0 ? health[0][j - 1] + dungeon[0][j] : -1;
    for (int i = 1; i < N; ++i)
    {
      health[i][0] = health[i - 1][0] >= 0 ? health[i - 1][0] + dungeon[i][0] : -1;
      for (int j = 1; j < M; ++j)
      {
        int t = Math.max(health[i - 1][j], health[i][j - 1]);
        health[i][j] = t >= 0 ? t + dungeon[i][j] : -1;
      }
    }
    return health[N - 1][M - 1] >= 0;
  }
}<commit_msg>(Dungeon Game) [Accepted] Correct DP<commit_after>public class Solution
{
  public int calculateMinimumHP (int[][] dungeon)
  {
    if (dungeon == null)
      throw new IllegalArgumentException();
    int N = dungeon.length;
    if (N == 0)
      throw new IllegalArgumentException();
    int M = dungeon[0].length;
    if (M == 0)
      throw new IllegalArgumentException();
    int[][] minHealth = new int[N][M];
    minHealth[N - 1][M - 1] = Math.max(-dungeon[N - 1][M - 1], 0);
    for (int j = M - 2; j >= 0; --j)
      minHealth[N - 1][j] = Math.max(minHealth[N - 1][j + 1] - dungeon[N - 1][j], 0);
    for (int i = N - 2; i >= 0; --i)
    {
      minHealth[i][M - 1] = Math.max(minHealth[i + 1][M - 1] - dungeon[i][M - 1], 0);
      for (int j = M - 2; j >= 0; --j)
        minHealth[i][j] = Math.max(Math.min(minHealth[i + 1][j], minHealth[i][j + 1]) - dungeon[i][j], 0);
    }
    return minHealth[0][0] + 1;
  }
}
{'fraction_non_alphanumeric': 0.19041218637992832, 'fraction_numerical': 0.03270609318996416, 'mean_word_length': 2.231548480463097, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1255170', 'n_tokens_mistral': 909, 'n_tokens_neox': 847, 'n_words': 236}