結果

問題 No.849 yuki国の分割統治
ユーザー leaf1415leaf1415
提出日時 2019-07-05 23:03:14
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,465 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 72,812 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-16 08:00:23
合計ジャッジ時間 3,934 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 96 ms
6,940 KB
testcase_08 AC 97 ms
7,168 KB
testcase_09 AC 96 ms
6,944 KB
testcase_10 AC 101 ms
6,944 KB
testcase_11 AC 87 ms
6,944 KB
testcase_12 AC 95 ms
6,940 KB
testcase_13 AC 103 ms
6,944 KB
testcase_14 AC 100 ms
6,940 KB
testcase_15 AC 92 ms
6,944 KB
testcase_16 AC 121 ms
8,960 KB
testcase_17 AC 95 ms
6,940 KB
testcase_18 AC 129 ms
9,344 KB
testcase_19 AC 102 ms
6,940 KB
testcase_20 AC 114 ms
7,680 KB
testcase_21 AC 86 ms
6,944 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 128 ms
10,368 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 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(a == 0 && c == 0){
		llint g = gcd(b, d);
		for(int i = 1; i <= n; i++){
			S.insert(make_pair(x[i], y[i]%g));
		}
		cout << S.size() << endl;
		return 0;
	}
	if(b == 0 && d == 0){
		llint g = gcd(a, c);
		for(int i = 1; i <= n; i++){
			S.insert(make_pair(x[i]%g, y[i]));
		}
		cout << S.size() << endl;
		return 0;
	}
	
	if(det == 0){
		llint gx = gcd(a, c), gy = (b, d);
		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