結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー mk_misuzumk_misuzu
提出日時 2015-12-18 23:46:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 891 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 60,460 KB
実行使用メモリ 4,716 KB
最終ジャッジ日時 2023-10-14 14:04:20
合計ジャッジ時間 3,845 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 40 ms
4,352 KB
testcase_19 WA -
testcase_20 AC 79 ms
4,548 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 67 ms
4,484 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 80 ms
4,540 KB
testcase_30 AC 3 ms
4,352 KB
testcase_31 AC 2 ms
4,352 KB
testcase_32 AC 41 ms
4,352 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 65 ms
4,680 KB
testcase_43 WA -
testcase_44 AC 59 ms
4,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* No.321 (P,Q)-サンタと街の子供たち */

#include <iostream>
#include <vector>

using namespace std;

typedef long long int Int;

Int gcd(Int m, Int n){
	if((m == 0) || (n == 0)) return 0;
	while(m != n){
		if(m > n) m -= n; else n -= m;
	}
	return m;
}

int main(){
	// 読み込み
	Int P, Q, N;
	cin >> P >> Q >> N;
	vector<Int> X, Y;
	for(Int i = 0; i < N; ++i){
		Int x, y;
		cin >> x >> y;
		X.push_back(x);
		Y.push_back(y);
	}
	// 計算
	if((P == 0) && (Q == 0)){
		cout << "0\n";
		return 0;
	}
	if((P == 0) && (Q != 0)) P = Q;
	if((P != 0) && (Q == 0)) Q = P;
	Int R = gcd(P, Q);
	Int sum = 0;
	for(Int i = 0; i < N; ++i){
		if((X[i] % R == 0) && (Y[i] % R == 0)){
			Int x = abs(X[i] / R), y = abs(Y[i] / R);
			if(x == y){
				++sum;
			}else{
				if((P % 2 == 0) && (Q % 2 == 1)) ++sum;
				if((P % 2 == 1) && (Q % 2 == 0)) ++sum;
			}
		}
	}
	cout << sum << "\n";
}
0