結果

問題 No.849 yuki国の分割統治
ユーザー jelljell
提出日時 2019-07-06 14:13:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 2,441 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 182,684 KB
実行使用メモリ 9,292 KB
最終ジャッジ日時 2024-04-16 08:32:38
合計ジャッジ時間 4,301 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 35 ms
6,944 KB
testcase_08 AC 40 ms
6,940 KB
testcase_09 AC 39 ms
6,944 KB
testcase_10 AC 39 ms
6,944 KB
testcase_11 AC 36 ms
6,940 KB
testcase_12 AC 38 ms
6,944 KB
testcase_13 AC 43 ms
6,940 KB
testcase_14 AC 39 ms
6,940 KB
testcase_15 AC 37 ms
6,940 KB
testcase_16 AC 53 ms
8,524 KB
testcase_17 AC 37 ms
6,944 KB
testcase_18 AC 52 ms
8,528 KB
testcase_19 AC 40 ms
6,940 KB
testcase_20 AC 49 ms
7,680 KB
testcase_21 AC 36 ms
6,940 KB
testcase_22 AC 46 ms
8,008 KB
testcase_23 AC 45 ms
7,808 KB
testcase_24 AC 36 ms
6,940 KB
testcase_25 AC 54 ms
9,292 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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();
}
0