結果
問題 | No.849 yuki国の分割統治 |
ユーザー |
![]() |
提出日時 | 2020-04-07 20:50:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 1,911 bytes |
コンパイル時間 | 2,240 ms |
コンパイル使用メモリ | 200,640 KB |
最終ジャッジ日時 | 2025-01-09 14:53:44 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 26 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define INF 1000000000 #define mod 1000000007 using ll=long long; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} ll A,B,C,D; void f(pair<ll,ll> u,pair<ll,ll> v){ if(v.first==0){ A=u.first;B=u.second; D=v.second; if(A<0){ A=-A;B=-B; } if(D<0) D=-D; return ; } if(u.first<v.first){ f(v,u); }else{ u.first-=v.first; u.second-=v.second; f(u,v); } } signed main(){ cin.tie(0); ios::sync_with_stdio(0); ll a,b,c,d;cin>>a>>b>>c>>d; int n;cin>>n; vector<pair<ll,ll>> v(n); rep(i,n) cin>>v[i].first>>v[i].second; if(a==0 and c==0){ swap(a,b);swap(c,d);rep(i,n)swap(v[i].first,v[i].second); } f(make_pair(a,b),make_pair(c,d)); //C=0 /* 代表点への移動 x' = x + k*A + l*0 y' = y + k*B + l*D 代表点は0<=x<Aかつ0<=y<Dとなる.これは各x,yに対し唯一必ず存在 */ set<pair<ll,ll>> st; for(auto p:v){ ll x=p.first,y=p.second; pair<ll,ll> res; ll k; if(x>=0){ res.first=x%A; k=-(x/A); }else{ k=(abs(x)+A-1)/A; res.first=x+k*A; } res.second=y+k*B; if(D!=0){ res.second=y+k*B; res.second%=D; res.second+=D; res.second%=D; } st.insert(res); } cout<<st.size()<<endl; return 0; }