結果

問題 No.849 yuki国の分割統治
ユーザー otoshigootoshigo
提出日時 2023-12-09 19:49:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,392 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 87,864 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2023-12-09 19:49:30
合計ジャッジ時間 3,281 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 37 ms
6,676 KB
testcase_08 AC 45 ms
7,040 KB
testcase_09 AC 43 ms
6,676 KB
testcase_10 AC 43 ms
6,676 KB
testcase_11 AC 40 ms
6,676 KB
testcase_12 AC 38 ms
6,676 KB
testcase_13 AC 47 ms
6,676 KB
testcase_14 AC 44 ms
6,676 KB
testcase_15 AC 43 ms
6,784 KB
testcase_16 AC 59 ms
8,960 KB
testcase_17 AC 36 ms
6,676 KB
testcase_18 AC 60 ms
9,216 KB
testcase_19 AC 44 ms
6,676 KB
testcase_20 AC 55 ms
7,680 KB
testcase_21 AC 27 ms
6,676 KB
testcase_22 AC 56 ms
8,448 KB
testcase_23 AC 54 ms
7,936 KB
testcase_24 AC 41 ms
6,676 KB
testcase_25 AC 65 ms
10,240 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<numeric>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    int N;
    cin>>N;
    vector<ll>X(N),Y(N);
    for(int i=0;i<N;i++)cin>>X[i]>>Y[i];
    if(a*d==b*c){
        if(a!=0||c!=0){
            set<pair<ll,ll>>se;
            ll g=gcd(a,c);
            for(int i=0;i<N;i++){
                ll p=b*X[i]-a*Y[i],q=X[i]%g;
                se.insert(make_pair(p,q));
            }
            cout<<se.size()<<"\n";
        }else{
            set<pair<ll,ll>>se;
            ll g=gcd(b,d);
            for(int i=0;i<N;i++){
                ll p=b*X[i]-a*Y[i],q=Y[i]%g;
                se.insert(make_pair(p,q));
            }
            cout<<se.size()<<"\n";
        }
    }else{
        set<pair<ll,ll>>se;
        ll M=abs(a*d-b*c);
        for(int i=0;i<N;i++){
            ll p=(d*X[i]-c*Y[i])%M,q=(-b*X[i]+a*Y[i])%M;
            if(p<0)p+=M;
            if(q<0)q+=M;
            se.insert(make_pair(p,q));
        }
        cout<<se.size()<<"\n";
    }
}
0