結果

問題 No.2406 Difference of Coordinate Squared
ユーザー momoyuumomoyuu
提出日時 2023-10-23 13:12:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 723 ms / 2,000 ms
コード長 1,659 bytes
コンパイル時間 1,400 ms
コンパイル使用メモリ 121,328 KB
実行使用メモリ 85,108 KB
最終ジャッジ日時 2023-10-23 13:13:06
合計ジャッジ時間 20,035 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 277 ms
19,268 KB
testcase_01 AC 287 ms
19,284 KB
testcase_02 AC 289 ms
19,400 KB
testcase_03 AC 723 ms
85,108 KB
testcase_04 AC 286 ms
19,400 KB
testcase_05 AC 287 ms
19,400 KB
testcase_06 AC 278 ms
19,276 KB
testcase_07 AC 281 ms
19,300 KB
testcase_08 AC 281 ms
19,272 KB
testcase_09 AC 281 ms
19,332 KB
testcase_10 AC 279 ms
19,276 KB
testcase_11 AC 287 ms
19,272 KB
testcase_12 AC 286 ms
19,272 KB
testcase_13 AC 280 ms
19,328 KB
testcase_14 AC 283 ms
19,272 KB
testcase_15 AC 281 ms
19,272 KB
testcase_16 AC 278 ms
19,276 KB
testcase_17 AC 276 ms
19,276 KB
testcase_18 AC 329 ms
27,536 KB
testcase_19 AC 285 ms
19,272 KB
testcase_20 AC 277 ms
19,272 KB
testcase_21 AC 282 ms
19,272 KB
testcase_22 AC 413 ms
52,108 KB
testcase_23 AC 280 ms
19,276 KB
testcase_24 AC 277 ms
19,276 KB
testcase_25 AC 287 ms
20,960 KB
testcase_26 AC 276 ms
19,272 KB
testcase_27 AC 277 ms
19,324 KB
testcase_28 AC 277 ms
19,272 KB
testcase_29 AC 277 ms
19,272 KB
testcase_30 AC 277 ms
19,272 KB
testcase_31 AC 277 ms
19,272 KB
testcase_32 AC 277 ms
19,272 KB
testcase_33 AC 277 ms
19,272 KB
testcase_34 AC 277 ms
19,272 KB
testcase_35 AC 276 ms
19,276 KB
testcase_36 AC 277 ms
19,272 KB
testcase_37 AC 278 ms
19,272 KB
testcase_38 AC 278 ms
19,272 KB
testcase_39 AC 278 ms
19,300 KB
testcase_40 AC 278 ms
19,272 KB
testcase_41 AC 277 ms
19,272 KB
testcase_42 AC 279 ms
19,396 KB
testcase_43 AC 277 ms
19,272 KB
testcase_44 AC 277 ms
19,272 KB
testcase_45 AC 277 ms
19,272 KB
testcase_46 AC 276 ms
19,272 KB
testcase_47 AC 278 ms
19,276 KB
testcase_48 AC 276 ms
19,332 KB
testcase_49 AC 277 ms
19,272 KB
testcase_50 AC 276 ms
19,272 KB
testcase_51 AC 278 ms
19,272 KB
testcase_52 AC 277 ms
19,272 KB
testcase_53 AC 277 ms
19,272 KB
testcase_54 AC 277 ms
19,272 KB
testcase_55 AC 278 ms
19,272 KB
testcase_56 AC 277 ms
19,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include<set>

using namespace std;
using ll = long long;

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


const int mx = 2e6 + 10;
mint fac[mx],ifac[mx];
mint comb(int n,int r){
    return fac[n] * ifac[r] * ifac[n-r];
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    ll n,m;
    cin>>n>>m;
    fac[0] = 1;
    for(int i = 1;i<mx;i++) fac[i] = fac[i-1] * i;
    for(int i = 0;i<mx;i++) ifac[i] = fac[i].inv();

    mint ans = 0;
    vector<pair<ll,ll>> use;
    if(m==0){
        for(int i = 1;i<=n;i++) {
            use.push_back(make_pair(0,i));
            use.push_back(make_pair(0,-i));
            use.push_back(make_pair(i,0));
            use.push_back(make_pair(-i,0));
        }
        use.push_back(make_pair(0,0));
    }
    for(ll i = 1;i*i<=abs(m);i++){
        if(m%i!=0) continue;
        ll a = i;
        ll b = m / i;
        use.push_back(make_pair(a,b));
        use.push_back(make_pair(-a,-b));
        swap(a,b);
        use.push_back(make_pair(a,b));
        use.push_back(make_pair(-a,-b));
    }
    sort(use.begin(),use.end());
    use.erase(unique(use.begin(),use.end()),use.end());
    for(int i = 0;i<use.size();i++){
        auto now = use[i];
        ll a = now.first;
        ll b = now.second;
        a = abs(a);
        b = abs(b);
        ll all = n;
        if(n%2!=a%2) continue;
        if(n%2!=b%2) continue;
        ll x = (a+n) / 2;
        ll y = (b+n) / 2;
        if(x>n||y>n) continue;
        ans += comb(n,x) * comb(n,y);
    }
    ans /= mint(4).pow(n);
    cout<<ans.val()<<endl;
    
}


0