結果

問題 No.2324 Two Countries within UEC
ユーザー HaaHaa
提出日時 2023-05-28 13:51:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,173 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 165,376 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 08:33:21
合計ジャッジ時間 8,688 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 236 ms
4,384 KB
testcase_01 AC 252 ms
4,380 KB
testcase_02 AC 45 ms
4,376 KB
testcase_03 AC 185 ms
4,380 KB
testcase_04 AC 218 ms
4,380 KB
testcase_05 AC 47 ms
4,376 KB
testcase_06 AC 86 ms
4,380 KB
testcase_07 AC 39 ms
4,376 KB
testcase_08 AC 187 ms
4,380 KB
testcase_09 AC 191 ms
4,380 KB
testcase_10 AC 251 ms
4,380 KB
testcase_11 AC 247 ms
4,380 KB
testcase_12 AC 75 ms
4,384 KB
testcase_13 AC 76 ms
4,376 KB
testcase_14 AC 45 ms
4,380 KB
testcase_15 AC 39 ms
4,380 KB
testcase_16 AC 167 ms
4,380 KB
testcase_17 AC 106 ms
4,380 KB
testcase_18 AC 50 ms
4,376 KB
testcase_19 AC 249 ms
4,380 KB
testcase_20 AC 33 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 254 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
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 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます

ソースコード

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.first==-1||r.first/x>m)
            cout << 0 << endl;
        else{
            ll k=m-r.first/x;
            cout << k/p+(r.first!=0) << endl;
        }
    }
    return 0;
}
0