結果

問題 No.849 yuki国の分割統治
ユーザー 👑 kmjpkmjp
提出日時 2019-07-05 22:02:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,344 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 171,112 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-16 07:19:36
合計ジャッジ時間 4,065 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 42 ms
5,504 KB
testcase_08 AC 54 ms
7,040 KB
testcase_09 AC 52 ms
6,528 KB
testcase_10 AC 49 ms
5,760 KB
testcase_11 AC 47 ms
6,144 KB
testcase_12 AC 44 ms
5,504 KB
testcase_13 AC 55 ms
6,656 KB
testcase_14 AC 51 ms
6,272 KB
testcase_15 AC 50 ms
7,040 KB
testcase_16 AC 69 ms
9,088 KB
testcase_17 AC 40 ms
5,376 KB
testcase_18 AC 71 ms
9,472 KB
testcase_19 AC 51 ms
6,144 KB
testcase_20 AC 65 ms
7,808 KB
testcase_21 AC 33 ms
5,376 KB
testcase_22 AC 67 ms
8,704 KB
testcase_23 AC 62 ms
8,064 KB
testcase_24 AC 47 ms
5,888 KB
testcase_25 AC 73 ms
10,496 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 <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll X[101010],Y[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	ll x1,y1,x2,y2;
	
	cin>>x1>>y1>>x2>>y2;
	
	if(x1==0 && x2==0) y1=__gcd(y1,y2);
	else if(y1==0 && y2==0) x1=__gcd(x1,x2);
	else {
		if(x2<x1) swap(x1,x2),swap(y1,y2);
		while(x1&&x2) {
			ll d=x2/x1;
			x2=x2-x1*d;
			y2=y2-y1*d;
			if(x2<x1) swap(x1,x2),swap(y1,y2);
		}
		if(x2<x1) swap(x1,x2),swap(y1,y2);
		
	}
	set<pair<ll,ll>> S;
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		if(x1==0 && x2==0) Y[i]%=y1;
		else if(y1==0 && y2==0) X[i]%=x1;
		else {
			ll d=X[i]/x2;
			X[i]-=x2*d;
			Y[i]-=y2*d;
			if(y1) Y[i]=(Y[i]%y1+y1)%y1;
		}
		
		S.insert({X[i],Y[i]});
	}
	
	
	cout<<S.size()<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0