結果

問題 No.849 yuki国の分割統治
ユーザー chocorusk
提出日時 2019-03-26 21:23:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,378 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 103,896 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-10-06 20:53:30
合計ジャッジ時間 4,325 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 5 WA * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
void extgcd(ll& a, ll& b, ll& c, ll& d){
	if(b==0) return;
	ll q=d/b;
	c-=a*q, d-=b*q;
	swap(a, c), swap(b, d);
	extgcd(a, b, c, d);
}
ll a, b, c, d;
int solve(){
    extgcd(a, b, c, d);
    if(a<=0) a=-a;
    c%=a;
    int n; cin>>n;
    set<P> st;
    for(int i=0; i<n; i++){
        ll x, y; cin>>x>>y;
        ll q=y/d;
        x-=q*c, y-=q*d;
        y=(y%a+a)%a;
        st.insert(P(x, y));
    }
    return st.size();
}
int solve0(){
    bool sw=0;
    if(b==0 && d==0){
        swap(a, b), swap(c, d);
        sw=1;
    }
    extgcd(a, b, c, d);
    ll p=c, q=d;
    int n; cin>>n;
    set<P> st;
    for(int i=0; i<n; i++){
        ll x, y; cin>>x>>y;
        if(sw) swap(x, y);
        ll t=y/q;
        x-=t*p, y-=t*q;
        st.insert(P(x, y));
    }
    return st.size();
}
int main()
{
    cin>>a>>b>>c>>d;
    if(a*d-b*c==0){
        cout<<solve0()<<endl;
    }else{
        cout<<solve()<<endl;
    }
    return 0;
}
0