結果
| 問題 |
No.849 yuki国の分割統治
|
| コンテスト | |
| ユーザー |
jell
|
| 提出日時 | 2019-07-06 14:13:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 2,441 bytes |
| コンパイル時間 | 2,284 ms |
| コンパイル使用メモリ | 186,924 KB |
| 実行使用メモリ | 9,420 KB |
| 最終ジャッジ日時 | 2024-10-06 23:53:32 |
| 合計ジャッジ時間 | 4,565 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using i64=int_fast64_t;
using pii=pair<int,int>;
using pll=pair<i64,i64>;
template <class T> constexpr T inf=numeric_limits<T>::max() / (T)2;
template <class T> using minheap=priority_queue<T,vector<T>,greater<T>>;
#define fir first
#define sec second
#define mkp make_pair
#define mkt make_tuple
#define emb emplace_back
#define emp emplace
#define all(v) begin(v),end(v)
namespace std {
template <class T> void hash_combine(size_t &seed, T const &key) {
seed ^= hash<T>()(key) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
template <class T, class U> struct hash<pair<T,U>> {
size_t operator()(pair<T,U> const &pr) const
{
size_t seed = 0;
hash_combine(seed,pr.first);
hash_combine(seed,pr.second);
return seed;
}
};
}
void ios_untie() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
void file_setup() {
if(!freopen("stderr.txt","wt",stderr)) {
std::cerr << "Failed to open the stderr file\n";
freopen("CON","wt",stderr);
}
if(!freopen("stdout.txt","wt",stdout)) {
std::cerr << "Failed to open the stdout file\n";
freopen("CON","wt",stdout);
}
if(!freopen("stdin.txt","rt",stdin)) {
std::cerr << "Failed to open the stdin file.\n";
freopen("CON","rt",stdin);
}
}
i64 binry(i64 ok, i64 ng, const function<bool(i64)> &f) {
while(abs(ok-ng)>1) {
i64 mid=(ok+ng)/2;
(f(mid) ? ok : ng) = mid;
}
return ok;
}
i64 gcd(i64 x,i64 y) {
return y?gcd(y,x%y):x;
}
i64 a,b,c,d;
int n;
pll cit[1<<17];
void solve() {
i64 det=abs(a*d-b*c);
int ans;
if(det) {
unordered_set<pll> S;
for(int i=0; i<n; ++i) {
i64 x,y; tie(x,y)=cit[i];
S.emplace(((d*x-c*y)%det+det)%det,((a*y-b*x)%det+det)%det);
}
ans=S.size();
} else {
i64 g=gcd(a,c);
i64 g2=gcd(b,d);
unordered_set<pll> S;
for(int i=0; i<n; ++i) {
i64 x,y; tie(x,y)=cit[i];
if(g) S.emplace(a*y-b*x,x%g);
else S.emplace(a*y-b*x,y%g2);
}
ans=S.size();
}
cout<<ans<<"\n";
}
signed main() {
ios_untie();
#ifdef LOCAL
file_setup();
#endif
cin>>a>>b>>c>>d>>n;
for(int i=0; i<n; ++i) {
cin>>cit[i].fir>>cit[i].sec;
}
solve();
}
jell