結果

問題 No.849 yuki国の分割統治
ユーザー ahe100ahe100
提出日時 2019-07-06 13:35:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 1,732 ms
コンパイル使用メモリ 168,616 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-16 08:32:05
合計ジャッジ時間 4,968 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,812 KB
testcase_03 AC 2 ms
6,820 KB
testcase_04 AC 2 ms
6,812 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 99 ms
6,944 KB
testcase_08 AC 108 ms
6,944 KB
testcase_09 AC 107 ms
6,944 KB
testcase_10 AC 104 ms
6,944 KB
testcase_11 AC 95 ms
6,940 KB
testcase_12 AC 97 ms
6,940 KB
testcase_13 AC 113 ms
6,940 KB
testcase_14 AC 108 ms
6,944 KB
testcase_15 AC 101 ms
6,940 KB
testcase_16 AC 135 ms
7,552 KB
testcase_17 AC 95 ms
6,944 KB
testcase_18 AC 138 ms
7,936 KB
testcase_19 AC 107 ms
6,940 KB
testcase_20 AC 129 ms
6,944 KB
testcase_21 AC 87 ms
6,944 KB
testcase_22 AC 131 ms
7,040 KB
testcase_23 AC 126 ms
6,940 KB
testcase_24 AC 103 ms
6,944 KB
testcase_25 AC 144 ms
8,704 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
同値類に分ける
*/

ll a,b,c,d,n;
set<pair<ll,ll>> s;

long long gcd(long long a,long long b){
	if(b==0)return a;
	return gcd(b,a%b);
}

void init(){
	cin>>a>>b>>c>>d>>n;
	ll det=abs(a*d-b*c);
	ll g1=gcd(a,c);
	ll g2=gcd(b,d);
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		if(det>0){
			s.insert({((d*x - c*y)%det + det)%det, ((-b*x + a*y)%det + det)%det});
		}else if(g1!=0){
			ll t=x/g1;
			if(x<0)t=t-1;
			s.insert({x-t*g1, y-t*g2});
		}else{
			ll t=y/g2;
			if(x<0)t=t-1;
			s.insert({x-t*g1, y-t*g2});
		}
	}
}

int main(void){
	init();
	cout<<s.size()<<endl;
	return 0;
}
0