Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int N, X, Y;
  scanf("%d %d %d", &N, &X, &Y);
  int count[N];
  for (int i = 0; i < N; ++i) {
    count[i] = 0;
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = i + 1; j <= N; ++j) {

      if (j - i >= (abs(X - i) + 1 + abs(j - Y))) {
        count[abs(X - i) + 1 + abs(j - Y)]++;
      } else {
        count[j - i]++;
      }
    }
  }

  for (int i = 1; i < N; ++i) {
    printf("%d\\n", count[i]);
  }

  return 0;
}
int A() {
  char Word[256];
  scanf("%s", &Word);
  if (Word[2] == Word[3] && Word[4] == Word[5]) {
    printf("Yes");
    return 0;
  }
  printf("No");
  return 0;
}

int B() {
  long long int money;
  scanf("%lld", &money);
  long long int happy1000;
  long long int happy5;
  happy1000 = money / 500;
  happy5 = (money % 500) / 5;

  printf("%lld", happy1000 * 1000 + happy5 * 5);
  return 0;
}

int C() {
  int K;
  int N;
  scanf("%d %d", &K, &N);
  int A[N + 1];
  int max = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  A[N] = A[0] + K;

  for (int i = 1; i <= N; ++i) {
    if (A[i] - A[i - 1] >= max) {
      max = A[i] - A[i - 1];
    }
  }
  printf("%d", K - max);
  return 0;
}

int floid_warshall() {
  int N, X, Y;
  scanf("%d %d %d", &N, &X, &Y);
  int DP[N + 1][N + 1];
  int count[N];
  int node[N + 1][N + 1];

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      node[i][j] = 2000;
      DP[i][j] = 2000;
    }
  }
  for (int i = 1; i < N; ++i) {
    count[i] = 0;
    node[i][i] = 0;
    node[i][i + 1] = 1;
    node[i + 1][i] = 1;
  }
  node[X][Y] = 1;
  node[Y][X] = 1;

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= N; ++k) {
        if (node[j][k] > node[j][i] + node[i][k]) {
          node[j][k] = node[j][i] + node[i][k];
        } else {
          node[j][k] = node[j][k];
        }
      }
    }
  }

  //    for (int i = 1; i <= N; ++i) {
  //        for (int j = 1; j <= N; j++) {
  //            printf("%d\\t",node[i][j]);
  //        }
  //        printf("\\n");
  //    }
  for (int i = 1; i <= N; ++i) {
    for (int j = i + 1; j <= N; ++j) {
      count[node[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; ++i) {
    printf("%d\\n", count[i]);
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  int N, X, Y;
  scanf("%d %d %d", &N, &X, &Y);
  int DP[N + 1][N + 1];
  int count[N];
  int node[N + 1][N + 1];

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j <= N; ++j) {
      node[i][j] = 2000;
      DP[i][j] = 2000;
    }
  }
  for (int i = 1; i < N; ++i) {
    count[i] = 0;
    node[i][i] = 0;
    node[i][i + 1] = 1;
    node[i + 1][i] = 1;
  }
  node[X][Y] = 1;
  node[Y][X] = 1;

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      for (int k = 1; k <= N; ++k) {
        if (node[j][k] > node[j][i] + node[i][k]) {
          node[j][k] = node[j][i] + node[i][k];
        } else {
          node[j][k] = node[j][k];
        }
      }
    }
  }

  //    for (int i = 1; i <= N; ++i) {
  //        for (int j = 1; j <= N; j++) {
  //            printf("%d\\t",node[i][j]);
  //        }
  //        printf("\\n");
  //    }
  for (int i = 1; i <= N; ++i) {
    for (int j = i + 1; j <= N; ++j) {
      count[node[i][j]]++;
    }
  }
  for (int i = 1; i <= N - 1; ++i) {
    printf("%d\\n", count[i]);
  }
  return 0;
}
int A() {
  char Word[256];
  scanf("%s", &Word);
  if (Word[2] == Word[3] && Word[4] == Word[5]) {
    printf("Yes");
    return 0;
  }
  printf("No");
  return 0;
}

int B() {
  long long int money;
  scanf("%lld", &money);
  long long int happy1000;
  long long int happy5;
  happy1000 = money / 500;
  happy5 = (money % 500) / 5;

  printf("%lld", happy1000 * 1000 + happy5 * 5);
  return 0;
}

int C() {
  int K;
  int N;
  scanf("%d %d", &K, &N);
  int A[N + 1];
  int max = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
  }
  A[N] = A[0] + K;

  for (int i = 1; i <= N; ++i) {
    if (A[i] - A[i - 1] >= max) {
      max = A[i] - A[i - 1];
    }
  }
  printf("%d", K - max);
  return 0;
}