結果

問題 No.1683 Robot Guidance
ユーザー auauaauaua
提出日時 2021-09-17 23:03:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 503 ms / 2,000 ms
コード長 2,216 bytes
コンパイル時間 1,637 ms
コンパイル使用メモリ 169,272 KB
実行使用メモリ 50,428 KB
最終ジャッジ日時 2023-09-12 09:07:10
合計ジャッジ時間 23,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 488 ms
50,264 KB
testcase_01 AC 488 ms
50,260 KB
testcase_02 AC 488 ms
50,312 KB
testcase_03 AC 490 ms
50,228 KB
testcase_04 AC 489 ms
50,232 KB
testcase_05 AC 489 ms
50,268 KB
testcase_06 AC 491 ms
50,244 KB
testcase_07 AC 490 ms
50,332 KB
testcase_08 AC 500 ms
50,192 KB
testcase_09 AC 491 ms
50,308 KB
testcase_10 AC 496 ms
50,188 KB
testcase_11 AC 495 ms
50,328 KB
testcase_12 AC 499 ms
50,264 KB
testcase_13 AC 489 ms
50,400 KB
testcase_14 AC 497 ms
50,312 KB
testcase_15 AC 489 ms
50,192 KB
testcase_16 AC 493 ms
50,228 KB
testcase_17 AC 489 ms
50,252 KB
testcase_18 AC 489 ms
50,188 KB
testcase_19 AC 488 ms
50,284 KB
testcase_20 AC 488 ms
50,364 KB
testcase_21 AC 488 ms
50,192 KB
testcase_22 AC 489 ms
50,192 KB
testcase_23 AC 488 ms
50,188 KB
testcase_24 AC 503 ms
50,308 KB
testcase_25 AC 488 ms
50,284 KB
testcase_26 AC 489 ms
50,312 KB
testcase_27 AC 489 ms
50,296 KB
testcase_28 AC 488 ms
50,188 KB
testcase_29 AC 488 ms
50,204 KB
testcase_30 AC 489 ms
50,312 KB
testcase_31 AC 488 ms
50,332 KB
testcase_32 AC 488 ms
50,196 KB
testcase_33 AC 492 ms
50,364 KB
testcase_34 AC 493 ms
50,192 KB
testcase_35 AC 491 ms
50,428 KB
testcase_36 AC 491 ms
50,232 KB
testcase_37 AC 491 ms
50,248 KB
testcase_38 AC 489 ms
50,252 KB
testcase_39 AC 489 ms
50,300 KB
testcase_40 AC 488 ms
50,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<random>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=INF;
const ll MAX=2000010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;

//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[MAX],finv[MAX],inv[MAX];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,MAX){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

void solve(){
    combinit();
    vector<ll>mo(4);
    ll a,b,x,y;cin>>a>>b>>x>>y;
    rep(i,b+1)mo[i%4]++;
    ll ans=0;
    REP(i,abs(x),a-abs(y)+1){
        if((i+x)%2)continue;
        ll q=comb(mo[0]-1+(i+x)/2,mo[0]-1);
        ll w=comb(mo[2]-1+(i-x)/2,mo[2]-1);
        if(mo[2]==0&&(i==x))w=1;
        if(mo[0]==0&&(-i==x))q=1;
        ll j=a-i;
        if((j+y)%2)continue;
        ll s=comb(mo[1]-1+(j+y)/2,mo[1]-1);
        ll d=comb(mo[3]-1+(j-y)/2,mo[3]-1);
        if(mo[3]==0&&(j==y))d=1;
        if(mo[1]==0&&(-j==y))s=1;
        ans=(ans+q*w%mod*s%mod*d%mod)%mod;
        //cout<<i<<' '<<q<<' '<<w<<' '<<s<<' '<<w<<endl;
    }
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0