結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-03-12 17:47:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,085 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 77,328 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 15:44:59
合計ジャッジ時間 4,735 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 RE -
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 39 ms
6,940 KB
testcase_15 AC 82 ms
6,940 KB
testcase_16 AC 31 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 38 ms
6,944 KB
testcase_19 AC 51 ms
6,940 KB
testcase_20 AC 78 ms
6,944 KB
testcase_21 AC 47 ms
6,940 KB
testcase_22 AC 15 ms
6,944 KB
testcase_23 AC 65 ms
6,944 KB
testcase_24 AC 18 ms
6,940 KB
testcase_25 AC 46 ms
6,944 KB
testcase_26 AC 76 ms
6,940 KB
testcase_27 AC 58 ms
6,944 KB
testcase_28 AC 55 ms
6,940 KB
testcase_29 AC 82 ms
6,944 KB
testcase_30 AC 3 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 40 ms
6,940 KB
testcase_33 AC 39 ms
6,940 KB
testcase_34 AC 29 ms
6,940 KB
testcase_35 AC 62 ms
6,944 KB
testcase_36 AC 5 ms
6,944 KB
testcase_37 AC 53 ms
6,940 KB
testcase_38 AC 43 ms
6,944 KB
testcase_39 AC 14 ms
6,944 KB
testcase_40 AC 73 ms
6,940 KB
testcase_41 AC 20 ms
6,944 KB
testcase_42 AC 64 ms
6,940 KB
testcase_43 AC 32 ms
6,944 KB
testcase_44 AC 59 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
using namespace std;
typedef long long lint;
typedef pair<lint,lint>pll;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

lint quo_nearest(lint a,lint b){
  lint q=a/b;
  lint r=a-q*b;
  if(abs(r)>abs(r-b))return q+1;
  if(abs(r)>abs(r+b))return q-1;
  return q;
}

pll rem_gaussian(pll a,pll b){
  lint bnorm=b.first*b.first+b.second*b.second;
  lint x=a.first*b.first+a.second*b.second;
  lint y=-a.first*b.second+a.second*b.first;
  lint qx=quo_nearest(x,bnorm);
  lint qy=quo_nearest(y,bnorm);
  return pll(a.first-qx*b.first+qy*b.second,a.second-qx*b.second-qy*b.first);
}

pll gcd_gaussian(pll a,pll b){
  while(b!=pll(0,0)){
    pll c=rem_gaussian(a,b);
    cerr<<"a="<<a.first<<" "<<a.second<<endl;
    cerr<<"b="<<b.first<<" "<<b.second<<endl;
    cerr<<"c="<<c.first<<" "<<c.second<<endl;
    a=b;b=c;
  }
  return a;
}

int main(){
  lint p,q;
  int n;
  cin>>p>>q>>n;
  pll g=gcd_gaussian(pll(p,q),pll(p,-q));
  int ans=0;
  rep(_,n){
    lint x,y;
    cin>>x>>y;
    ans+=rem_gaussian(pll(x,y),g)==pll(0,0)?1:0;
  }
  cout<<ans<<endl;
}
0