結果

問題 No.2406 Difference of Coordinate Squared
ユーザー silv723silv723
提出日時 2023-08-04 22:24:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 5,279 bytes
コンパイル時間 4,316 ms
コンパイル使用メモリ 266,848 KB
実行使用メモリ 50,304 KB
最終ジャッジ日時 2024-05-05 01:40:16
合計ジャッジ時間 10,608 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
50,176 KB
testcase_01 AC 94 ms
50,176 KB
testcase_02 AC 104 ms
50,176 KB
testcase_03 AC 138 ms
50,176 KB
testcase_04 AC 88 ms
50,176 KB
testcase_05 AC 85 ms
50,176 KB
testcase_06 AC 79 ms
50,176 KB
testcase_07 AC 83 ms
50,304 KB
testcase_08 AC 84 ms
50,176 KB
testcase_09 AC 85 ms
50,176 KB
testcase_10 AC 81 ms
50,176 KB
testcase_11 AC 94 ms
50,176 KB
testcase_12 AC 94 ms
50,048 KB
testcase_13 AC 85 ms
50,176 KB
testcase_14 AC 83 ms
50,176 KB
testcase_15 AC 89 ms
50,176 KB
testcase_16 AC 88 ms
50,176 KB
testcase_17 AC 79 ms
50,176 KB
testcase_18 AC 128 ms
50,176 KB
testcase_19 AC 89 ms
50,176 KB
testcase_20 AC 78 ms
50,176 KB
testcase_21 AC 86 ms
50,176 KB
testcase_22 AC 125 ms
50,176 KB
testcase_23 AC 80 ms
50,176 KB
testcase_24 AC 75 ms
50,176 KB
testcase_25 AC 122 ms
50,176 KB
testcase_26 AC 77 ms
50,176 KB
testcase_27 AC 122 ms
50,176 KB
testcase_28 AC 76 ms
50,176 KB
testcase_29 AC 77 ms
50,176 KB
testcase_30 AC 73 ms
50,176 KB
testcase_31 AC 72 ms
50,176 KB
testcase_32 AC 74 ms
50,048 KB
testcase_33 AC 75 ms
50,176 KB
testcase_34 AC 73 ms
50,176 KB
testcase_35 AC 73 ms
50,048 KB
testcase_36 AC 79 ms
50,176 KB
testcase_37 AC 75 ms
50,176 KB
testcase_38 AC 75 ms
50,176 KB
testcase_39 AC 115 ms
50,304 KB
testcase_40 AC 72 ms
50,304 KB
testcase_41 AC 73 ms
50,048 KB
testcase_42 AC 117 ms
50,176 KB
testcase_43 AC 75 ms
50,176 KB
testcase_44 AC 74 ms
50,176 KB
testcase_45 AC 74 ms
50,176 KB
testcase_46 AC 84 ms
50,176 KB
testcase_47 AC 77 ms
50,048 KB
testcase_48 AC 117 ms
50,176 KB
testcase_49 AC 73 ms
50,048 KB
testcase_50 AC 74 ms
50,176 KB
testcase_51 AC 74 ms
50,176 KB
testcase_52 AC 74 ms
50,176 KB
testcase_53 AC 77 ms
50,176 KB
testcase_54 AC 79 ms
50,176 KB
testcase_55 AC 75 ms
50,176 KB
testcase_56 AC 108 ms
50,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
using i128 = __int128_t;
#define vs vector<string>
#define rep(i,n) for(ll i=0;i<ll(n);i++)
#define rep2(i,n) for(ll i=n-1;i>=0;i--)
#define rep3(i,a,b) for(ll i=a;i<=ll(b);i++)
#define rep4(i,a,b) for(ll i=a;i>=ll(b);i--)
#define forv(i,V) for(const auto& i:V)
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define SIZE(x) int(x.size())
constexpr ll mod=998244353;
//constexpr ll mod=1000000007;
#define pi 3.14159265358979323
#define INF32 2147483647
#define INF64 9223372036854775807
#define faster ios::sync_with_stdio(false);std::cin.tie(nullptr)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rev reverse
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define prq priority_queue
#define lb lower_bound
#define ub upper_bound
#define popcnt __builtin_popcountll
#define TLE while(true);
#define RE assert(false);
#define MLE vector<vector<vector<long long>>> mle_mle(400,vector<vector<long long>>(1000,vector<long long>(1000)));
const string YESNO[2] = {"NO", "YES"};
const string YesNo[2] = {"No", "Yes"};
const string yesno[2] = {"no", "yes"};
#define rall(n) (n).rbegin(),(n).rend()
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
template<typename T,typename U>
ostream &operator<<(ostream&os,const pair<T,U>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T,typename U>
istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v){for(auto it=v.begin();it!=v.end();){os<<*it<<((++it)!=v.end()?" ":"");}return os;}
template<typename T>
istream &operator>>(istream&is,vector<T>&v){for(T &in:v){is>>in;}return is;}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail){cin>>head;scan(tail...);}
template<class T>
void print(const T &t){cout<<t<<'\n';}
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail){cout<<head<<' ';print(tail...);}
template<class... T>
void fin(const T &... a){print(a...);exit(0);}
ll max(int a,ll b){return max((ll)a,b);}
ll max(ll a,int b){return max((ll)b,a);}
ll min(int a,ll b){return min((ll)a,b);}
ll min(ll a,int b){return min((ll)b,a);}
//a以上b以下の個数
template<typename T>
ll RangeOK(ll a,ll b,vector<T> &v){
  return max(ub(all(v),b)-lb(all(v),a),0);
}
template <typename T>
vector<T> compress(vector<T> &X) {
    vector<T> vals = X;
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 0; i < (int)X.size(); i++) {
        X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
    }
    return vals;
}
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
const int MOD = 998244353;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}
ll modpow(ll n, ll k){
  ll ret = 1;
  while(k){
    if(k&1) ret = ret*n%mod;
    n = n*n%mod;
    k >>= 1;
  }
  return ret;
}
ll n, m;
ll f(ll a, ll b){
  //print(a, b);
  if(abs(n)%2 != abs(a)%2) return 0;
  if(abs(n)%2 != abs(b)%2) return 0;
  ll p = (n+a)/2;
  ll q = (n+b)/2;
  //print(p, q);
  return nCk(n, p)*nCk(n, q)%mod;
}
int main(){
  init_nCk(2000000);
  scan(n, m);
  ll ans = 0;
  for(ll i = 1; i*i <= abs(m); i++){
    if(abs(m)%i == 0){
      ans += f(i, m/i);
      ans += f(-i, -m/i);
      if(i != abs(m)/i){
        ans += f(m/i, i);
        ans += f(-m/i, -i);
      }
      ans %= mod;
    }
  }
  if(m == 0){
    ans += f(0, 0);
    rep3(i, 1, 2000000){
      ans += f(0, i);
      ans %= mod;
    }
    rep3(i, 1, 2000000){
      ans += f(0, -i);
      ans %= mod;
    }
    rep3(i, 1, 2000000){
      ans += f(i, 0);
      ans %= mod;
    }
    rep3(i, 1, 2000000){
      ans += f(-i, 0);
      ans %= mod;
    }
  }
  ll inv = 1;
  rep(i, n) inv = inv*4%mod;
  //print(ans, inv);
  inv = modpow(inv, mod-2);
  fin(ans*inv%mod);
}
0