結果

問題 No.849 yuki国の分割統治
ユーザー jelljell
提出日時 2019-07-06 14:10:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 181,084 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2024-04-16 08:32:34
合計ジャッジ時間 4,562 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 44 ms
6,940 KB
testcase_08 AC 51 ms
7,168 KB
testcase_09 AC 52 ms
6,944 KB
testcase_10 AC 50 ms
6,944 KB
testcase_11 AC 47 ms
6,940 KB
testcase_12 AC 46 ms
6,940 KB
testcase_13 AC 55 ms
6,940 KB
testcase_14 AC 52 ms
6,944 KB
testcase_15 AC 50 ms
6,948 KB
testcase_16 AC 69 ms
9,216 KB
testcase_17 AC 43 ms
6,940 KB
testcase_18 AC 71 ms
9,472 KB
testcase_19 AC 52 ms
6,944 KB
testcase_20 AC 63 ms
7,936 KB
testcase_21 AC 35 ms
6,944 KB
testcase_22 AC 63 ms
8,448 KB
testcase_23 AC 58 ms
7,936 KB
testcase_24 AC 47 ms
6,940 KB
testcase_25 AC 77 ms
10,368 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 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)
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) {
        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);
        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