結果

問題 No.321 (P,Q)-サンタと街の子供たち
ユーザー TatamoTatamo
提出日時 2016-04-19 19:00:11
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,635 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 67,716 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-15 03:46:01
合計ジャッジ時間 4,775 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 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 1 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 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <cmath>

#define MAX 100000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lp;


lp f(ll p, ll q){
	if(p > q) { // maybe needless
		swap(p,q);
	}
	if(p != 0){
		// p <= q
		// get min(|2xp-q|)
		ll tmp = p*2;
		ll x = p/tmp; // <=> 2xp-q == 0
		ll ans = min((ll)abs(x*tmp-q),(ll)abs((x+1)*tmp-q)); // min is x or x+1
		lp result;
		if(ans <= p){
			result.first = ans;
			result.second = p;
		}
		else {
			result.first = p;
			result.second = q;
		}
		return result;
	}
	else{
		lp result;
		result.first = p;
		result.second = q;
		return result;
	}
}

int main(){
	ll p,q;
	cin >> p >> q;
	if(p > q) { // always p<=q
		swap(p,q);
	}
	int n;
	cin >> n;
	lp* children = new lp[n];
	for(int i=0; i<n; i++){
		lp pos;
		ll tmp;
		cin >> tmp;
		pos.first = (ll)abs(tmp);
		cin >> tmp;
		pos.second = (ll)abs(tmp);
		children[i] = pos;
	}
	lp pos;
	pos.first = p;
	pos.second = q;
	while(true){
		pos = f(pos.first, pos.second);
		if(pos.first <= 0 ||  pos.first == pos.second){
			break;
		}
	}

	int result = 0;
	if(pos.first == 0 && pos.second == 0){
		for(int i=0; i<n; i++){
			if(children[i].first == 0 && children[i].second == 0){
				result++;
			}
		}
	}
	else if(pos.first == 0){
		for(int i=0; i<n; i++){
			if(children[i].first % pos.second == 0 && children[i].second % pos.second == 0){
				result++;
			}
		}
	}
	else { // pos.first == pos.second
		for(int i=0; i<n; i++){
			if((children[i].first + children[i].second)%(pos.first*2) == 0){
				result++;
			}
		}
	}
	cout << result << endl;
	return 0;
}
0