結果
| 問題 |
No.849 yuki国の分割統治
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2019-07-05 23:22:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,619 bytes |
| コンパイル時間 | 2,080 ms |
| コンパイル使用メモリ | 204,996 KB |
| 最終ジャッジ日時 | 2025-01-07 06:11:32 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 RE * 1 |
| other | AC * 7 RE * 5 TLE * 14 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct UnionFind{
Int n,num;
vector<Int> r,p;
UnionFind(){}
UnionFind(Int sz):n(sz),num(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
Int find(Int x){
return (x==p[x]?x:p[x]=find(p[x]));
}
bool same(Int x,Int y){
return find(x)==find(y);
}
void unite(Int x,Int y){
x=find(x);y=find(y);
if(x==y) return;
if(r[x]<r[y]) swap(x,y);
r[x]+=r[y];
p[y]=x;
num--;
}
Int size(Int x){
return r[find(x)];
}
Int count() const{
return num;
}
};
template<typename T>
vector<T> compress(vector<T> v){
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
return v;
}
template<typename T>
map<T, Int> dict(const vector<T> &v){
map<T, Int> res;
for(Int i=0;i<(Int)v.size();i++)
res[v[i]]=i;
return res;
}
//INSERT ABOVE HERE
signed main(){
Int a,b,c,d;
cin>>a>>b>>c>>d;
Int n;
cin>>n;
vector<Int> xs(n),ys(n);
for(Int i=0;i<n;i++) cin>>xs[i]>>ys[i];
while(a*d-b*c==0);
UnionFind uf(n);
vector<Int> vs;
for(Int i=0;i<n;i++){
for(Int v:vs){
Int x=xs[i]-xs[v];
Int y=ys[i]-ys[v];
Int p=(c*y-d*x)/(b*c-a*d);
Int q=(a*y-b*x)/(a*d-b*c);
if(a*p+c*q==x&&b*p+d*q==y) uf.unite(i,v);
}
vector<Int> nx;
for(Int v:vs)
nx.emplace_back(uf.find(v));
nx.emplace_back(uf.find(i));
vs=compress(nx);
}
cout<<uf.count()<<endl;
return 0;
}
beet