結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー amai_amai_taroamai_amai_taro
提出日時 2020-05-23 02:14:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,724 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 167,420 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-15 23:22:04
合計ジャッジ時間 6,947 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 134 ms
5,376 KB
testcase_15 AC 103 ms
5,376 KB
testcase_16 AC 42 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 62 ms
5,376 KB
testcase_19 AC 74 ms
5,376 KB
testcase_20 AC 113 ms
5,376 KB
testcase_21 AC 73 ms
5,376 KB
testcase_22 AC 19 ms
5,376 KB
testcase_23 AC 114 ms
5,376 KB
testcase_24 AC 37 ms
5,376 KB
testcase_25 AC 83 ms
5,376 KB
testcase_26 AC 178 ms
5,376 KB
testcase_27 AC 134 ms
5,376 KB
testcase_28 AC 121 ms
5,376 KB
testcase_29 AC 205 ms
5,376 KB
testcase_30 AC 5 ms
5,376 KB
testcase_31 AC 4 ms
5,376 KB
testcase_32 AC 94 ms
5,376 KB
testcase_33 AC 84 ms
5,376 KB
testcase_34 AC 106 ms
5,376 KB
testcase_35 AC 205 ms
5,376 KB
testcase_36 AC 8 ms
5,376 KB
testcase_37 AC 189 ms
5,376 KB
testcase_38 AC 166 ms
5,376 KB
testcase_39 AC 48 ms
5,376 KB
testcase_40 AC 303 ms
5,376 KB
testcase_41 AC 80 ms
5,376 KB
testcase_42 AC 291 ms
5,376 KB
testcase_43 AC 144 ms
5,376 KB
testcase_44 AC 236 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int64_t in_div(int64_t n,int64_t m){
  if((n>=0 && m>=0)||(0>=n && 0>=m)){
    n=abs(n);
    m=abs(m);
    return (2*n/m+1)/2;
  }
  else{
    n=abs(n);
    m=abs(m);
    return -(2*n/m+1)/2;
  }
}

pair<int64_t,int64_t> co_mul(pair<int64_t,int64_t> a,pair<int64_t,int64_t> b){
  pair<int64_t,int64_t> ans(a.first*b.first-a.second*b.second,b.first*a.second+a.first*b.second);
  return ans;
}

pair<int64_t,int64_t> co_div(pair<int64_t,int64_t> a,pair<int64_t,int64_t> b){
  int64_t mod=b.first*b.first+b.second*b.second;
  b.second=-b.second;
  pair<int64_t,int64_t> mul(co_mul(a,b).first,co_mul(a,b).second);
  pair<int64_t,int64_t> ans(in_div(mul.first,mod),in_div(mul.second,mod));
  return ans;
}

pair<int64_t,int64_t> co_rem(pair<int64_t,int64_t> a,pair<int64_t,int64_t> b){
  pair<int64_t,int64_t> div(co_div(a,b).first,co_div(a,b).second);
  pair<int64_t,int64_t> ans(a.first-co_mul(b,div).first,a.second-co_mul(b,div).second);
  return ans;
}

pair<int64_t,int64_t> co_GCD(pair<int64_t,int64_t> a,pair<int64_t,int64_t> b){
  if(co_rem(a,b).first==0 && co_rem(a,b).second==0){
    return b;
  }
  return co_GCD(b,co_rem(a,b));
}

int main(){
  int64_t P,Q,N;
  cin>>P>>Q>>N;
  vector<pair<int64_t,int64_t>> kid(N);
  for(int i=0;i<N;i++){
    cin>>kid.at(i).first>>kid.at(i).second;
  }
  pair<int64_t,int64_t> V1(P,Q);
  pair<int64_t,int64_t> V2(P,-Q);
  pair<int64_t,int64_t> zero(0,0);
  int ans=0;
  if(P==0 && Q==0){
    for(int i=0;i<N;i++){
      if(kid.at(i)==zero){
        ans++;
      }
    }
    cout<<ans<<endl;
  }
  else{
    for(int i=0;i<N;i++){
      if(co_rem(kid.at(i),co_GCD(V1,V2))==zero){
        ans++;
      }
    }
    cout<<ans<<endl;
  }
  
}
0