結果

問題 No.849 yuki国の分割統治
ユーザー b312546656b312546656
提出日時 2019-07-05 22:21:32
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 2,980 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 83,416 KB
実行使用メモリ 9,412 KB
最終ジャッジ日時 2024-04-16 07:39:41
合計ジャッジ時間 4,379 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 RE -
testcase_08 AC 85 ms
7,780 KB
testcase_09 AC 88 ms
7,472 KB
testcase_10 AC 96 ms
7,168 KB
testcase_11 AC 80 ms
7,336 KB
testcase_12 AC 91 ms
6,656 KB
testcase_13 AC 92 ms
7,420 KB
testcase_14 AC 92 ms
7,164 KB
testcase_15 AC 81 ms
7,440 KB
testcase_16 AC 99 ms
8,636 KB
testcase_17 AC 94 ms
6,528 KB
testcase_18 AC 99 ms
8,896 KB
testcase_19 AC 96 ms
7,296 KB
testcase_20 AC 97 ms
8,120 KB
testcase_21 AC 88 ms
6,528 KB
testcase_22 AC 100 ms
8,512 KB
testcase_23 AC 100 ms
8,128 KB
testcase_24 AC 96 ms
7,168 KB
testcase_25 AC 98 ms
9,412 KB
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 3 ms
5,376 KB
testcase_29 AC 3 ms
5,376 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 >> y >> x;
				int ex = per(x, a);
				int ey = y - ((x - ex) / a)*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