結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー kuuso1
提出日時 2015-11-23 19:47:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 114,824 KB
実行使用メモリ 30,384 KB
最終ジャッジ日時 2024-07-06 21:45:26
合計ジャッジ時間 5,543 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 41
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
プレゼンテーションモードにする

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class TEST{
static void Main(){
Sol mySol =new Sol();
mySol.Solve();
}
}
class Sol{
public void Solve(){
int cnt=0;
int gcd=calgcd(P,Q);
for(int i=0;i<N;i++){
// P==0Q==0 (0,0)
if(P==0 && Q==0){
if(X[i]==0 && Y[i]==0)cnt++;
continue;
}
// P==0Q==0P>0(resp. Q>0)(X,Y)P(resp. Q)
if(P==0 || Q==0){
if(P>0 && X[i]%P==0 && Y[i]%P==0)cnt++;
if(Q>0 && X[i]%Q==0 && Y[i]%Q==0)cnt++;
continue;
}
//P,Q>0
// gcd NG
if(X[i]%gcd!=0 || Y[i]%gcd!=0)continue;
int P0=P/gcd;
int Q0=Q/gcd;
int X0=X[i]/gcd;
int Y0=Y[i]/gcd;
// P0 Q0 gcd OK
if(P0%2==0 || Q0%2==0){
cnt++;
continue;
}
// P0 Q0 (,) (,)
if((X0+Y0)%2==0){
cnt++;
continue;
}
}
Console.WriteLine(cnt);
}
static int calgcd(int a,int b){
return a==0?b:calgcd(b%a,a);
}
int P,Q;
int N;
int[] X,Y;
public Sol(){
var d=ria();
P=d[0];Q=d[1];
N=ri();
X=new int[N];
Y=new int[N];
for(int i=0;i<N;i++){
var dd=ria();
X[i]=dd[0];Y[i]=dd[1];
}
}
static int ri(){return int.Parse(Console.ReadLine());}
static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0