結果

問題 No.2406 Difference of Coordinate Squared
ユーザー otoshigootoshigo
提出日時 2023-08-04 23:10:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,085 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 83,860 KB
実行使用メモリ 26,824 KB
最終ジャッジ日時 2024-04-22 21:33:27
合計ジャッジ時間 7,103 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
26,700 KB
testcase_01 AC 84 ms
26,640 KB
testcase_02 AC 76 ms
26,588 KB
testcase_03 WA -
testcase_04 AC 121 ms
26,524 KB
testcase_05 AC 78 ms
26,588 KB
testcase_06 AC 79 ms
26,616 KB
testcase_07 AC 68 ms
26,656 KB
testcase_08 AC 72 ms
26,592 KB
testcase_09 AC 181 ms
26,524 KB
testcase_10 AC 86 ms
26,660 KB
testcase_11 AC 76 ms
26,736 KB
testcase_12 AC 71 ms
26,748 KB
testcase_13 AC 203 ms
26,736 KB
testcase_14 AC 76 ms
26,732 KB
testcase_15 AC 80 ms
26,700 KB
testcase_16 AC 99 ms
26,640 KB
testcase_17 AC 69 ms
26,668 KB
testcase_18 WA -
testcase_19 AC 84 ms
26,684 KB
testcase_20 AC 90 ms
26,752 KB
testcase_21 AC 69 ms
26,620 KB
testcase_22 WA -
testcase_23 AC 146 ms
26,632 KB
testcase_24 AC 79 ms
26,528 KB
testcase_25 WA -
testcase_26 AC 76 ms
26,528 KB
testcase_27 WA -
testcase_28 AC 62 ms
26,504 KB
testcase_29 AC 68 ms
26,704 KB
testcase_30 AC 74 ms
26,588 KB
testcase_31 AC 66 ms
26,588 KB
testcase_32 AC 69 ms
26,668 KB
testcase_33 AC 71 ms
26,528 KB
testcase_34 AC 62 ms
26,816 KB
testcase_35 AC 60 ms
26,660 KB
testcase_36 AC 66 ms
26,736 KB
testcase_37 AC 69 ms
26,664 KB
testcase_38 AC 72 ms
26,692 KB
testcase_39 WA -
testcase_40 AC 60 ms
26,664 KB
testcase_41 AC 63 ms
26,592 KB
testcase_42 WA -
testcase_43 AC 70 ms
26,676 KB
testcase_44 AC 73 ms
26,684 KB
testcase_45 AC 64 ms
26,648 KB
testcase_46 AC 59 ms
26,820 KB
testcase_47 AC 60 ms
26,660 KB
testcase_48 WA -
testcase_49 AC 72 ms
26,620 KB
testcase_50 AC 76 ms
26,584 KB
testcase_51 AC 58 ms
26,660 KB
testcase_52 AC 61 ms
26,520 KB
testcase_53 AC 61 ms
26,628 KB
testcase_54 AC 77 ms
26,664 KB
testcase_55 AC 76 ms
26,624 KB
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
using namespace std;
using ll=long long;
using mint=atcoder::modint998244353;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll MOD=998244353;
const int MAX=2e6+10;
vector<mint>fac(MAX),finv(MAX),inv(MAX);

void set_fac(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i;
        inv[i]=-inv[MOD%i]*(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}

mint cmb(int n,int r){
    if (r<0||n<r)return 0;
    return fac[n]*finv[r]*finv[n-r];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    set_fac();
    ll N,M;
    cin>>N>>M;
    M=abs(M);
    ll p=1;
    mint ans=0,P4=mint(4).pow(N);
    if(M==0){
        if(N%2!=0)cout<<0<<"\n";
        else{
            for(int x=0;x<=N;x+=2){
                ans+=fac[N]*finv[x/2]*finv[x/2]*finv[(N-x)/2]*finv[(N-x)/2];
            }
            ans/=P4;
            cout<<ans.val()<<"\n";
            return 0;
        }
    }
    while(p*p<=M){
        if(M%p==0){
            int q=M/p;
            if((p+q)%2==0){
                ll x=abs((p+q)/2),y=abs((p-q)/2);
                if((x+y)%2==N%2){
                    for(int i=x;i<=N;i+=2){
                        int b=(i-x)/2,a=x+b;
                        int j=N-i;
                        int d=(j-y)/2,c=y+d;
                        if(d>=0){
                            mint r=fac[N]*finv[a]*finv[b]*finv[c]*finv[d];
                            if(x==0&&y==0)ans+=r;
                            else if(x==0||y==0)ans+=2*r;
                            else ans+=4*r;
                        }
                    }
                }
            }
        }
        p++;
    }
    ans/=P4;
    cout<<ans.val()<<"\n";
}
0