結果

問題 No.849 yuki国の分割統治
ユーザー square1001square1001
提出日時 2019-07-05 21:50:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,213 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 89,604 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-04-16 07:13:53
合計ジャッジ時間 3,139 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 ms
5,376 KB
testcase_07 AC 45 ms
5,376 KB
testcase_08 AC 51 ms
6,912 KB
testcase_09 AC 47 ms
6,400 KB
testcase_10 AC 46 ms
5,504 KB
testcase_11 AC 43 ms
6,016 KB
testcase_12 AC 42 ms
5,376 KB
testcase_13 AC 51 ms
6,528 KB
testcase_14 AC 48 ms
5,888 KB
testcase_15 AC 48 ms
6,656 KB
testcase_16 AC 67 ms
8,832 KB
testcase_17 AC 38 ms
5,376 KB
testcase_18 AC 70 ms
9,088 KB
testcase_19 AC 48 ms
5,888 KB
testcase_20 AC 59 ms
7,552 KB
testcase_21 AC 31 ms
5,376 KB
testcase_22 AC 65 ms
8,192 KB
testcase_23 AC 62 ms
7,808 KB
testcase_24 AC 46 ms
5,632 KB
testcase_25 AC 74 ms
9,984 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <set>
#include <cmath>
#include <tuple>
#include <vector>
#include <cassert>
#include <iostream>
using namespace std;
long long gcd(long long x, long long y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	long long A, B, C, D; int N;
	cin >> A >> B >> C >> D >> N;
	vector<long long> X(N), Y(N);
	for (int i = 0; i < N; ++i) {
		cin >> X[i] >> Y[i];
	}
	if (B * C - A * D != 0) {
		set<pair<long long, long long> > d;
		for (int i = 0; i < N; ++i) {
			long long xc = B * X[i] - A * Y[i];
			long long yc = D * X[i] - C * Y[i];
			bool xt = false, yt = false;
			if (xc < 0) xt = true, xc *= -1;
			xc %= abs(B * C - A * D);
			if (xt && xc != 0) xc = abs(B * C - A * D) - xc;
			if (yc < 0) yt = true, yc *= -1;
			yc %= abs(D * A - C * B);
			if (yt && yc != 0) yc = abs(D * A - C * B) - yc;
			d.insert(make_pair(xc, yc));
		}
		cout << d.size() << endl;
	}
	else {
		long long gx = gcd(A, C), gy = gcd(B, D);
		long long g = gcd(gx, gy);
		set<tuple<long long, long long, long long> > d;
		for (int i = 0; i < N; ++i) {
			d.insert(make_tuple(gy * X[i] - gx * Y[i], X[i] % g, Y[i] % g));
		}
		cout << d.size() << endl;
	}
	return 0;
}
0