結果

問題 No.849 yuki国の分割統治
ユーザー i_mrhji_mrhj
提出日時 2019-08-08 12:26:20
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,366 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 33,152 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 10:15:05
合計ジャッジ時間 2,901 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

typedef struct { ll x, y; } R;

ll
rem(ll a, ll b)
{
  if (a < 0 && a % b < 0) return a % b + b;
  return a % b;
}

int
Rsort(const void *a, const void *b)
{
  R A = *(R *)a, B = *(R *)b;
  if (A.x == B.x && A.y == B.y) return  0;
  if (A.x < B.x) return -1;
  if (A.x > B.x) return  1;
  if (A.y < B.y) return -1;
  return 1;
}

int
main(int argc, char **argv)
{
  ll a, b, c, d;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  
  int n;
  scanf("%d", &n);
  
  if (a * d - b * c != 0) {
    ll p = a * d - b * c;
    ll x, y;
    R r[100000];
    for (int i = 0; i < n; i++) {
      scanf("%lld %lld", &x, &y);
      r[i].x = rem(d * x - c * y, p);
      r[i].y = rem(a * y - b * x, p);
      printf("%lld %lld\n", r[i].x, r[i].y);
    }
    

    qsort(r, n, sizeof(R), Rsort);

    int cnt = 1;
    for (int i = 0; i < n - 1; i++) {
      if (r[i].x != r[i + 1].x || r[i].y != r[i + 1].y) cnt++;
    }

    printf("%d\n", cnt);
  }

  return 0;
}

    
  
0