結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 RE -
testcase_08 AC 53 ms
7,168 KB
testcase_09 AC 51 ms
6,944 KB
testcase_10 AC 49 ms
6,944 KB
testcase_11 AC 46 ms
6,944 KB
testcase_12 AC 50 ms
6,940 KB
testcase_13 AC 56 ms
6,940 KB
testcase_14 AC 52 ms
6,940 KB
testcase_15 AC 49 ms
7,040 KB
testcase_16 AC 75 ms
9,216 KB
testcase_17 AC 41 ms
6,940 KB
testcase_18 AC 70 ms
9,344 KB
testcase_19 AC 51 ms
6,940 KB
testcase_20 AC 63 ms
7,808 KB
testcase_21 AC 35 ms
6,940 KB
testcase_22 AC 62 ms
8,576 KB
testcase_23 AC 63 ms
8,192 KB
testcase_24 AC 46 ms
6,944 KB
testcase_25 AC 79 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);
        set<pll> S;
        for(int i=0; i<n; ++i) {
            i64 x,y; tie(x,y)=cit[i];
            S.emplace(a*y-b*x,x%g);
        }
        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