結果

問題 No.2324 Two Countries within UEC
ユーザー HaaHaa
提出日時 2023-05-28 14:00:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 1,718 ms
コンパイル使用メモリ 166,540 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 06:10:01
合計ジャッジ時間 8,810 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
4,380 KB
testcase_01 AC 254 ms
4,380 KB
testcase_02 AC 45 ms
4,380 KB
testcase_03 AC 189 ms
4,380 KB
testcase_04 AC 221 ms
4,380 KB
testcase_05 AC 48 ms
4,376 KB
testcase_06 AC 87 ms
4,380 KB
testcase_07 AC 40 ms
4,376 KB
testcase_08 AC 188 ms
4,380 KB
testcase_09 AC 194 ms
4,376 KB
testcase_10 AC 256 ms
4,380 KB
testcase_11 AC 252 ms
4,376 KB
testcase_12 AC 78 ms
4,380 KB
testcase_13 AC 77 ms
4,380 KB
testcase_14 AC 45 ms
4,376 KB
testcase_15 AC 41 ms
4,380 KB
testcase_16 AC 169 ms
4,376 KB
testcase_17 AC 109 ms
4,376 KB
testcase_18 AC 51 ms
4,380 KB
testcase_19 AC 253 ms
4,380 KB
testcase_20 AC 34 ms
4,380 KB
testcase_21 AC 172 ms
4,380 KB
testcase_22 AC 222 ms
4,380 KB
testcase_23 AC 70 ms
4,380 KB
testcase_24 AC 184 ms
4,380 KB
testcase_25 AC 256 ms
4,376 KB
testcase_26 AC 205 ms
4,376 KB
testcase_27 AC 212 ms
4,380 KB
testcase_28 AC 199 ms
4,384 KB
testcase_29 AC 194 ms
4,380 KB
testcase_30 AC 201 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

ll extgcd(ll a, ll b, ll &x, ll &y) {
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll gcd=extgcd(b,a%b,x,y);
    ll oldX=x;
    x=y;
    y=oldX-a/b*y;
    return gcd;
}

P crt2(ll b1, ll m1, ll b2, ll m2){
    ll x, y;
    ll d=extgcd(m1,m2,x,y);
    if((b2-b1)%d!=0)
        return {0,-1};
    else{
        ll m=m1*(m2/d);
        return {((b1+((b2-b1)/d)*x%(m2/d)*m1)%m+m)%m,m};
    }
}

int main(){
    ll n, m, p, q;
    cin >> n >> m >> p >> q;
    ll x, f;
    REP(i,q){
        cin >> x >> f;
        P r=crt2(f,p,0,x);
        if(r.second==-1||r.first/x>m)
            cout << 0 << endl;
        else{
            ll k=m-r.first/x;
            if(x%p==0)
                cout << k+(r.first!=0) << endl;
            else
                cout << k/p+(r.first!=0) << endl;
        }
    }
    return 0;
}
0