結果

問題 No.849 yuki国の分割統治
ユーザー LayCurseLayCurse
提出日時 2019-07-05 23:10:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 3,322 bytes
コンパイル時間 2,415 ms
コンパイル使用メモリ 199,544 KB
実行使用メモリ 8,136 KB
最終ジャッジ日時 2024-04-16 08:03:44
合計ジャッジ時間 3,702 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 18 ms
7,624 KB
testcase_08 AC 17 ms
6,940 KB
testcase_09 AC 17 ms
7,756 KB
testcase_10 AC 18 ms
7,756 KB
testcase_11 AC 16 ms
8,136 KB
testcase_12 AC 18 ms
6,944 KB
testcase_13 AC 18 ms
8,032 KB
testcase_14 AC 18 ms
7,632 KB
testcase_15 AC 17 ms
7,624 KB
testcase_16 AC 18 ms
7,756 KB
testcase_17 AC 17 ms
7,632 KB
testcase_18 AC 19 ms
7,496 KB
testcase_19 AC 19 ms
7,756 KB
testcase_20 AC 19 ms
7,632 KB
testcase_21 AC 12 ms
7,756 KB
testcase_22 AC 19 ms
8,092 KB
testcase_23 AC 19 ms
6,944 KB
testcase_24 AC 18 ms
7,632 KB
testcase_25 AC 19 ms
7,628 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr=(pair<T1, T2> *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
char memarr[96000000];
long long A;
long long B;
long long C;
long long D;
long long N;
long long X[100000];
long long Y[100000];
long long xy[100000];
int sz;
int main(){
  int i, j, k, res=0;
  long long d, xx, yy;
  wmem = memarr;
  rd(A);
  rd(B);
  rd(C);
  rd(D);
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
      rd(Y[Lj4PdHRW]);
    }
  }
  d = A*D - B*C;
  if(d < 0){
    d = -d;
  }
  if( d == 0 ){
    if(A==C && C==0){
      i =GCD_L(B, D);
      A = 0;
      B = i;
    }
    else{
      i =GCD_L(A, C);
      B = B * i / A;
      A = i;
    }
    for(k=0;k<N;k++){
      if(A){
        i = X[k] / A;
        X[k] -= A * i;
        Y[k] -= B * i;
      }
      else{
        i = Y[k] / B;
        X[k] -= A * i;
        Y[k] -= B * i;
      }
    }
  }
  else{
    for(k=0;k<N;k++){
      xx = X[k];
      yy = Y[k];
      X[k] = (xx * D - yy * C) % d;
      Y[k] = (yy * A - xx * B) % d;
      if(X[k] < 0){
        X[k] += d;
      }
      if(Y[k] < 0){
        Y[k] += d;
      }
    }
  }
  sortA_L(N, X, Y);
  for(i=0;i<N;i++){
    if(i==0 || X[i]!=X[i-1] || Y[i]!=Y[i-1]){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190630-1

// --- original code ---
// ll A, B, C, D, N, X[1d5], Y[1d5];
// 
// ll xy[1d5]; int sz;
// {
//   int i, j, k;
//   ll d, xx, yy;
//   int res = 0;
//   rd(A,B,C,D,N,(X,Y)(N));
// 
//   d = A*D - B*C;
//   if(d < 0) d = -d;
//   
//   if( d == 0 ){
//     if(A==C==0){
//       i = gcd(B, D);
//       A = 0;
//       B = i;
//     } else {
//       i = gcd(A, C);
//       B = B * i / A;
//       A = i;
//     }
// 
//     rep(k,N){
//       if(A){
//         i = X[k] / A;
//         X[k] -= A * i;
//         Y[k] -= B * i;
//       } else {
//         i = Y[k] / B;
//         X[k] -= A * i;
//         Y[k] -= B * i;
//       }
//     }
//   } else {
//     rep(k,N){
//       xx = X[k];
//       yy = Y[k];
//       X[k] = (xx * D - yy * C) % d;
//       Y[k] = (yy * A - xx * B) % d;
//       if(X[k] < 0) X[k] += d;
//       if(Y[k] < 0) Y[k] += d;
//     }
//   }
//   
//   sortA(N, X, Y);
//   rep(i,N) if(i==0 || X[i]!=X[i-1] || Y[i]!=Y[i-1]) res++;
//   wt(res);
// }
0