結果

問題 No.2517 Right Triangles on Circle
コンテスト
ユーザー chro_96
提出日時 2023-10-27 23:44:41
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 790 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 166 ms
コンパイル使用メモリ 39,652 KB
最終ジャッジ日時 2026-02-22 11:19:45
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int cmp_int (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  int m = 0;
  int a[300000] = {};
  
  int res = 0;
  
  long long ans = 0LL;
  int idx = 0;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
  }
  
  if (m%2 == 1) {
    printf("0\n");
    return 0;
  }
  
  qsort(a, n, sizeof(int), cmp_int);
  for (int i = 0; i < n; i++) {
    while (idx < n && a[idx] < a[i]+m/2) {
      idx++;
    }
    if (idx < n && a[idx] == a[i]+m/2) {
      ans += 1LL;
    }
  }
  
  ans *= (long long)(n-2);
  printf("%lld\n", ans);
  return 0;
}
0