結果

問題 No.849 yuki国の分割統治
ユーザー leaf1415leaf1415
提出日時 2019-07-05 22:56:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 606 ms
コンパイル使用メモリ 72,296 KB
実行使用メモリ 11,264 KB
最終ジャッジ日時 2024-04-16 07:58:09
合計ジャッジ時間 3,924 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 96 ms
7,040 KB
testcase_09 AC 98 ms
6,940 KB
testcase_10 AC 100 ms
6,940 KB
testcase_11 AC 89 ms
6,940 KB
testcase_12 AC 95 ms
6,940 KB
testcase_13 AC 103 ms
6,944 KB
testcase_14 AC 101 ms
6,944 KB
testcase_15 AC 91 ms
6,940 KB
testcase_16 AC 122 ms
8,960 KB
testcase_17 AC 93 ms
6,944 KB
testcase_18 AC 127 ms
9,216 KB
testcase_19 AC 102 ms
6,940 KB
testcase_20 AC 115 ms
7,680 KB
testcase_21 AC 86 ms
6,940 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 131 ms
10,368 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 1 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <utility>
#include <set>
#include <stdlib.h>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint a, b, c, d;
llint n;
llint x[100005], y[100005];

llint gcd(llint a, llint b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(void)
{
	cin >> a >> b >> c >> d;
	cin >> n;
	
	llint det = a*d-b*c;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	
	set<P> S;
	if(det == 0){
		x[10000000];
		llint gx = gcd(a, c), gy = (b, d);
		//cout << gx << " " << gy << endl;
		for(int i = 1; i <= n; i++){
			llint bunsi = gx*y[i]-gy*x[i], bunbo = gx;
			//cout << bunsi << " " << bunbo << endl;
			llint g = gcd(abs(bunsi), abs(bunbo));
			if(bunbo == 0) g = 1;
			S.insert(make_pair(bunsi/g, bunbo/g));
		}
		cout << S.size() << endl;
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		det = abs(det);
		llint bunsi1 = x[i]*d-y[i]*c, bunsi2 = a*y[i]-x[i]*b;
		if(bunsi1 < 0) bunsi1 = det - abs(bunsi1)%det;
		if(bunsi2 < 0) bunsi2 = det - abs(bunsi2)%det;
		bunsi1 %= det, bunsi2 %= det;
		S.insert(make_pair(bunsi1, bunsi2));
	}
	cout << S.size() << endl;
	
	return 0;
}
0