結果

問題 No.849 yuki国の分割統治
ユーザー kotatsugamekotatsugame
提出日時 2019-07-07 19:37:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 797 bytes
コンパイル時間 689 ms
コンパイル使用メモリ 74,668 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2024-04-16 09:06:52
合計ジャッジ時間 4,661 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 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 121 ms
5,376 KB
testcase_08 AC 122 ms
6,656 KB
testcase_09 AC 120 ms
5,376 KB
testcase_10 AC 117 ms
5,376 KB
testcase_11 AC 109 ms
5,504 KB
testcase_12 AC 110 ms
5,376 KB
testcase_13 AC 128 ms
5,760 KB
testcase_14 AC 122 ms
5,376 KB
testcase_15 AC 114 ms
6,144 KB
testcase_16 AC 150 ms
8,576 KB
testcase_17 AC 106 ms
5,376 KB
testcase_18 AC 157 ms
8,832 KB
testcase_19 AC 124 ms
5,376 KB
testcase_20 AC 148 ms
7,040 KB
testcase_21 AC 91 ms
5,376 KB
testcase_22 AC 209 ms
8,064 KB
testcase_23 AC 185 ms
7,424 KB
testcase_24 AC 122 ms
5,376 KB
testcase_25 AC 170 ms
10,112 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
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<set>
using namespace std;
long a,b,c,d;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
int N;
set<pair<pair<long,long>,pair<long,long> > >S;
pair<long,long>f(pair<long,long>p)
{
	p.first=(p.first%p.second+p.second)%p.second;
	return p;
}
main()
{
	cin>>a>>b>>c>>d>>N;
	long t=a*d-b*c;
	int ans=N;
	for(int i=0;i<N;i++)
	{
		long x,y;cin>>x>>y;
		pair<long,long>p,q;
		if(t==0)
		{
			long A=gcd(a,c),B=gcd(b,d);
			if(A)
			{
				long X=x/A;
				x-=X*A;
				y-=X*B;
			}
			else
			{
				long X=y/B;
				x-=X*A;
				y-=X*B;
			}
			p=make_pair(x,y);
			q=make_pair(0,0);
		}
		else
		{
			p.first=d*x-c*y;
			q.first=-b*x+a*y;
			p.second=q.second=t;
			p=f(p);
			q=f(q);
		}
		ans-=S.find(make_pair(p,q))!=S.end();
		S.insert(make_pair(p,q));
	}
	cout<<ans<<endl;
}
0