結果

問題 No.849 yuki国の分割統治
ユーザー chocoruskchocorusk
提出日時 2019-03-26 19:09:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 1,567 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 104,400 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-16 06:57:31
合計ジャッジ時間 4,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 97 ms
5,376 KB
testcase_08 AC 102 ms
5,888 KB
testcase_09 AC 101 ms
5,376 KB
testcase_10 AC 103 ms
5,376 KB
testcase_11 AC 94 ms
5,376 KB
testcase_12 AC 97 ms
5,376 KB
testcase_13 AC 111 ms
5,376 KB
testcase_14 AC 106 ms
5,376 KB
testcase_15 AC 95 ms
5,504 KB
testcase_16 AC 130 ms
7,424 KB
testcase_17 AC 94 ms
5,376 KB
testcase_18 AC 134 ms
7,808 KB
testcase_19 AC 107 ms
5,376 KB
testcase_20 AC 124 ms
6,272 KB
testcase_21 AC 86 ms
5,376 KB
testcase_22 AC 127 ms
6,912 KB
testcase_23 AC 121 ms
6,528 KB
testcase_24 AC 99 ms
5,376 KB
testcase_25 AC 137 ms
8,704 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
ll lcm(ll a, ll b){
    return a/gcd(a, b)*b;
}
void extgcd(ll& a, ll& b, ll& c, ll& d){
	if(c==0) return;
	ll q=a/c;
	a-=c*q, b-=d*q;
	swap(a, c), swap(b, d);
	extgcd(a, b, c, d);
}
ll a, b, c, d;
int solve(){
    extgcd(a, b, c, d);
    b%=d;
    int n; cin>>n;
    set<P> st;
    for(int i=0; i<n; i++){
        ll x, y; cin>>x>>y;
        ll q=x/a;
        x-=q*a, y-=q*b;
        y=(y%d+d)%d;
        st.insert(P(x, y));
    }
    return st.size();
}
int solve0(){

    ll g1=gcd(a, c), g2=gcd(b, d);
    ll s=lcm((g1!=0 ? a/g1 : 1), (g2!=0 ? b/g2 : 1));
    ll p=a/s, q=b/s;
    int n; cin>>n;
    set<P> st;
    for(int i=0; i<n; i++){
        ll x, y; cin>>x>>y;
        if(p==0){
            ll t=y/q;
            x-=t*p, y-=t*q;
            st.insert(P(x, y));
        }else{
            ll t=x/p;
            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