結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー kuuso1kuuso1
提出日時 2015-11-23 19:47:21
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 3,046 ms
コンパイル使用メモリ 107,020 KB
実行使用メモリ 28,932 KB
最終ジャッジ日時 2023-09-21 03:06:21
合計ジャッジ時間 10,313 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,744 KB
testcase_01 AC 58 ms
22,824 KB
testcase_02 AC 58 ms
20,776 KB
testcase_03 AC 59 ms
22,708 KB
testcase_04 AC 59 ms
20,716 KB
testcase_05 AC 60 ms
22,764 KB
testcase_06 AC 59 ms
22,904 KB
testcase_07 AC 58 ms
20,768 KB
testcase_08 AC 60 ms
22,768 KB
testcase_09 AC 60 ms
20,800 KB
testcase_10 AC 60 ms
20,788 KB
testcase_11 AC 59 ms
20,784 KB
testcase_12 AC 59 ms
22,876 KB
testcase_13 AC 59 ms
20,860 KB
testcase_14 AC 117 ms
27,052 KB
testcase_15 AC 151 ms
27,332 KB
testcase_16 AC 95 ms
26,864 KB
testcase_17 AC 59 ms
20,756 KB
testcase_18 AC 103 ms
24,812 KB
testcase_19 AC 118 ms
26,952 KB
testcase_20 AC 149 ms
25,196 KB
testcase_21 AC 113 ms
22,784 KB
testcase_22 AC 74 ms
24,812 KB
testcase_23 AC 135 ms
27,056 KB
testcase_24 AC 80 ms
26,928 KB
testcase_25 AC 110 ms
24,956 KB
testcase_26 AC 145 ms
27,288 KB
testcase_27 AC 123 ms
25,004 KB
testcase_28 AC 122 ms
27,036 KB
testcase_29 AC 150 ms
25,160 KB
testcase_30 AC 62 ms
22,868 KB
testcase_31 AC 61 ms
22,876 KB
testcase_32 AC 105 ms
26,888 KB
testcase_33 AC 105 ms
28,932 KB
testcase_34 AC 92 ms
24,860 KB
testcase_35 AC 130 ms
27,064 KB
testcase_36 AC 61 ms
20,912 KB
testcase_37 AC 114 ms
24,996 KB
testcase_38 AC 104 ms
27,060 KB
testcase_39 AC 73 ms
24,828 KB
testcase_40 AC 146 ms
25,140 KB
testcase_41 AC 82 ms
22,928 KB
testcase_42 AC 132 ms
25,228 KB
testcase_43 AC 95 ms
24,780 KB
testcase_44 AC 126 ms
22,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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==0かつQ==0 なら (0,0)のみ到達可能
			if(P==0 && Q==0){
				if(X[i]==0 && Y[i]==0)cnt++;
				continue;
			}
			
			// P==0またはQ==0の場合、P>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));}
}
0