結果

問題 No.849 yuki国の分割統治
ユーザー b312546656b312546656
提出日時 2019-07-05 22:23:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 2,957 bytes
コンパイル時間 1,044 ms
コンパイル使用メモリ 84,024 KB
実行使用メモリ 9,636 KB
最終ジャッジ日時 2023-07-28 23:44:23
合計ジャッジ時間 4,260 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,872 KB
testcase_01 AC 3 ms
4,748 KB
testcase_02 AC 3 ms
4,628 KB
testcase_03 AC 3 ms
4,960 KB
testcase_04 AC 3 ms
4,796 KB
testcase_05 AC 3 ms
4,780 KB
testcase_06 AC 3 ms
4,868 KB
testcase_07 AC 89 ms
6,768 KB
testcase_08 AC 79 ms
7,496 KB
testcase_09 AC 82 ms
7,360 KB
testcase_10 AC 89 ms
6,984 KB
testcase_11 AC 74 ms
6,920 KB
testcase_12 AC 85 ms
6,748 KB
testcase_13 AC 87 ms
7,436 KB
testcase_14 AC 86 ms
7,156 KB
testcase_15 AC 75 ms
7,476 KB
testcase_16 AC 92 ms
8,568 KB
testcase_17 AC 87 ms
6,572 KB
testcase_18 AC 92 ms
9,104 KB
testcase_19 AC 90 ms
7,216 KB
testcase_20 AC 92 ms
8,108 KB
testcase_21 AC 83 ms
6,480 KB
testcase_22 AC 94 ms
8,312 KB
testcase_23 AC 92 ms
7,980 KB
testcase_24 AC 90 ms
6,892 KB
testcase_25 AC 93 ms
9,636 KB
testcase_26 AC 3 ms
4,716 KB
testcase_27 AC 3 ms
4,776 KB
testcase_28 AC 3 ms
4,800 KB
testcase_29 AC 3 ms
4,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_program(s) cout << s <<endl;return 0
int kai_size = 120001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4); 
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, kai_size-1) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}
int gcd(int a, int b) {
	a = abs(a);
	b = abs(b);
	if (a < b) { swap(a, b); }
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
int per(int a, int b) {
	int ans = a % b;
	if (ans < 0) { ans += b; }
	return ans;
}
V<pin> uni(V<pin> &v) {
	sor(v);
	V<pin> ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i-1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
signed main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a*d - b * c == 0) {
		int gcd0 = gcd(a, b);
		int pa =a/ gcd0;
		int pb =b/ gcd0;
		int g1;
		if (pa != 0) {g1 = c / pa;}
		else {g1 = d / pb;}
		a = pa*gcd(gcd0, g1);
		b = pb*gcd(gcd0, g1);
		int n; cin >> n;
		V<pin> ans(n);
		if (a != 0) {
			rep(i, n) {
				int x, y; cin >> x >> y;
				int ex = per(x, a);
				int ey = y-((x - ex)/ a)*b;
				ans[i]=mkp(ex, ey);
			}
		}
		else {
			rep(i, n) {
				int x, y; cin >> x >> y;
				int ex = x;
				int ey = y % b;
				ans[i]=mkp(ex, ey);
			}
		}
		uni(ans);
		cout << ans.size() << Endl;
	}
	else {
		int det = a * d - b * c;
		det = abs(det);
		int n; cin >> n;
		V<pin> ans(n);
		rep(i, n) {
			int x, y; cin >> x >> y;
			int nx = d * x - c * y;
			nx = per(nx, det);
			int ny = a * y - b * x;
			ny = per(ny, det);
			ans[i]=mkp(nx, ny);
		}
		uni(ans);
		cout << ans.size() << Endl;
	}
	return 0;
}
0