結果

問題 No.2406 Difference of Coordinate Squared
ユーザー 👑 獅子座じゃない人獅子座じゃない人
提出日時 2023-07-12 02:01:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 171,980 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-11-26 18:00:16
合計ジャッジ時間 5,011 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/modint>
using namespace atcoder;
using mint=modint998244353;

int main(void)
{
    long long n,m;
    cin >> n >> m;
    m=abs(m);
    vector<mint> fact(n+1,1);
    vector<mint> fact_inv(n+1,1);
    for(int i=1;i<=n;++i){
        fact[i]=fact[i-1]*i;
        fact_inv[i]=fact_inv[i-1]/i;
    }
    mint ans=0;
    for(long long y=0;y<=n;++y){
        long long x=sqrt(y*y+m);
        if(x*x-y*y!=m){
            continue;
        }
        if(x+y>n){
            break;
        }
        if((n-x-y)%2){
            continue;
        }
        long long a=x+(n-x-y)/2;
        long long b=(n-x-y)/2;
        if(a>n){
            continue;
        }
        if(x && y){
            ans+=4*fact[n]*fact_inv[a]*fact_inv[n-a]*fact[n]*fact_inv[b]*fact_inv[n-b];
        } else if(x || y){
            ans+=2*fact[n]*fact_inv[a]*fact_inv[n-a]*fact[n]*fact_inv[b]*fact_inv[n-b];
        } else {
            ans+=fact[n]*fact_inv[a]*fact_inv[n-a]*fact[n]*fact_inv[b]*fact_inv[n-b];
        }
    }
    ans/=mint(4).pow(n);
    cout << ans.val() << endl;
    return 0;
}
0