結果

問題 No.849 yuki国の分割統治
ユーザー 👑 jupirojupiro
提出日時 2020-01-21 18:53:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,096 bytes
コンパイル時間 1,209 ms
コンパイル使用メモリ 120,676 KB
実行使用メモリ 8,740 KB
最終ジャッジ日時 2023-09-20 03:29:33
合計ジャッジ時間 5,936 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 53 ms
5,860 KB
testcase_09 AC 49 ms
4,952 KB
testcase_10 AC 46 ms
4,376 KB
testcase_11 AC 45 ms
4,960 KB
testcase_12 AC 40 ms
4,376 KB
testcase_13 AC 53 ms
5,104 KB
testcase_14 AC 49 ms
4,688 KB
testcase_15 AC 50 ms
5,628 KB
testcase_16 AC 71 ms
7,568 KB
testcase_17 AC 36 ms
4,376 KB
testcase_18 AC 72 ms
7,812 KB
testcase_19 AC 47 ms
4,380 KB
testcase_20 AC 63 ms
6,260 KB
testcase_21 AC 27 ms
4,380 KB
testcase_22 AC 62 ms
8,224 KB
testcase_23 AC 59 ms
7,636 KB
testcase_24 AC 44 ms
5,192 KB
testcase_25 AC 82 ms
8,740 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll gcd(ll x, ll y)
{
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll adbc = llabs(a * d - b * c);
	ll n; scanf("%lld", &n);
	ll res = 0;
	set<pair<ll, ll>> s;
	if (adbc == 0) {
		vector<ll> x(n), y(n); for (ll i = 0; i < n; i++) scanf("%lld %lld", &x[i], &y[i]);
		if (gcd(a, c) == 0) {
			swap(a, c);
			swap(b, d);
			for (ll i = 0; i < n; i++) swap(x[i], y[i]);
		}
		ll e, f;
		a = extGCD(a, c, e, f);
		b = b * e + d * f;
		for (ll i = 0; i < n; i++) {
			auto p = make_pair(x[i] % a, y[i] - x[i] / a * b);
			s.insert(p);
		}
	}
	else {

		for (ll i = 0; i < n; i++) {
			ll x, y; scanf("%lld %lld", &x, &y);
			ll r1 = d * x - c * y;
			ll r2 = -b * x + a * y;
			r1 %= adbc;
			r2 %= adbc;
			if (r1 < 0) r1 += adbc;
			if (r2 < 0) r2 += adbc;
			auto p = make_pair(r1, r2);
			//cout <<i<< " "<< r1 << " " << r2 << endl;
			s.insert(p);
		}
	}
	cout << s.size() << endl;
	return 0;
}
0