結果
問題 | No.2406 Difference of Coordinate Squared |
ユーザー | shobonvip |
提出日時 | 2023-08-04 23:05:33 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 379 ms / 2,000 ms |
コード長 | 2,772 bytes |
コンパイル時間 | 5,110 ms |
コンパイル使用メモリ | 266,520 KB |
実行使用メモリ | 21,120 KB |
最終ジャッジ日時 | 2024-05-05 01:41:17 |
合計ジャッジ時間 | 8,550 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
20,864 KB |
testcase_01 | AC | 44 ms
20,992 KB |
testcase_02 | AC | 97 ms
21,120 KB |
testcase_03 | AC | 41 ms
20,864 KB |
testcase_04 | AC | 347 ms
20,992 KB |
testcase_05 | AC | 40 ms
20,864 KB |
testcase_06 | AC | 51 ms
20,992 KB |
testcase_07 | AC | 37 ms
20,992 KB |
testcase_08 | AC | 36 ms
20,864 KB |
testcase_09 | AC | 349 ms
20,864 KB |
testcase_10 | AC | 75 ms
20,992 KB |
testcase_11 | AC | 41 ms
20,864 KB |
testcase_12 | AC | 41 ms
20,864 KB |
testcase_13 | AC | 379 ms
20,864 KB |
testcase_14 | AC | 68 ms
20,864 KB |
testcase_15 | AC | 49 ms
20,864 KB |
testcase_16 | AC | 65 ms
20,864 KB |
testcase_17 | AC | 34 ms
20,864 KB |
testcase_18 | AC | 32 ms
20,992 KB |
testcase_19 | AC | 39 ms
20,992 KB |
testcase_20 | AC | 62 ms
20,864 KB |
testcase_21 | AC | 40 ms
20,864 KB |
testcase_22 | AC | 35 ms
20,864 KB |
testcase_23 | AC | 199 ms
20,864 KB |
testcase_24 | AC | 54 ms
20,864 KB |
testcase_25 | AC | 32 ms
20,864 KB |
testcase_26 | AC | 33 ms
20,864 KB |
testcase_27 | AC | 33 ms
20,992 KB |
testcase_28 | AC | 32 ms
20,864 KB |
testcase_29 | AC | 32 ms
20,864 KB |
testcase_30 | AC | 32 ms
20,864 KB |
testcase_31 | AC | 33 ms
20,992 KB |
testcase_32 | AC | 32 ms
20,864 KB |
testcase_33 | AC | 31 ms
20,864 KB |
testcase_34 | AC | 32 ms
20,864 KB |
testcase_35 | AC | 32 ms
20,864 KB |
testcase_36 | AC | 32 ms
20,864 KB |
testcase_37 | AC | 32 ms
20,864 KB |
testcase_38 | AC | 31 ms
20,992 KB |
testcase_39 | AC | 31 ms
20,992 KB |
testcase_40 | AC | 31 ms
20,864 KB |
testcase_41 | AC | 32 ms
20,864 KB |
testcase_42 | AC | 33 ms
20,864 KB |
testcase_43 | AC | 34 ms
20,992 KB |
testcase_44 | AC | 33 ms
21,120 KB |
testcase_45 | AC | 34 ms
20,992 KB |
testcase_46 | AC | 33 ms
20,864 KB |
testcase_47 | AC | 36 ms
20,864 KB |
testcase_48 | AC | 33 ms
20,864 KB |
testcase_49 | AC | 33 ms
20,864 KB |
testcase_50 | AC | 33 ms
20,864 KB |
testcase_51 | AC | 33 ms
20,864 KB |
testcase_52 | AC | 32 ms
20,992 KB |
testcase_53 | AC | 33 ms
20,864 KB |
testcase_54 | AC | 33 ms
20,864 KB |
testcase_55 | AC | 33 ms
20,864 KB |
testcase_56 | AC | 32 ms
20,864 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } // makediv vector<ll> makediv(ll n){ vector<ll> ld, ud; for (ll i=1; i*i<=n; i++){ if (n%i == 0){ ld.push_back(i); if (i != n/i){ ud.push_back(n/i); } } } reverse(ud.begin(), ud.end()); ld.insert(ld.end(), ud.begin(), ud.end()); return ld; } // ----- //defmodfact const int COMinitMAX = 2222222; mint fact[COMinitMAX+1], factinv[COMinitMAX+1]; void modfact(){ fact[0] = 1; for (int i=1; i<=COMinitMAX; i++){ fact[i] = fact[i-1] * i; } factinv[COMinitMAX] = fact[COMinitMAX].inv(); for (int i=COMinitMAX-1; i>=0; i--){ factinv[i] = factinv[i+1] * (i+1); } } mint cmb(int a, int b){ if (a<b || b<0) return mint(0); return fact[a]*factinv[b]*factinv[a-b]; } //-------- int main(){ modfact(); int n; cin >> n; ll m; cin >> m; mint ans = 0; if (m != 0){ m = abs(m); vector<ll> g = makediv(m); for (ll d: g){ if (abs(d + m / d) % 2 != 0 || abs(d - m / d) % 2 != 0) continue; mint bai = 2; //if (abs(d + m / d) == abs(d - m / d)) bai = 1; ll x = abs(d + m / d) / 2; ll y = abs(d - m / d) / 2; //cout << d << " " << m / d << '\n'; if (abs(x) + abs(y) > n) continue; for (ll k=0; k<=n; k++){ if ((k+x)%2 == 1) continue; if ((n-k+y)%2 == 1) continue; ans += bai * cmb(k, (k+x)/2) * cmb(n-k, (n-k+y)/2) * cmb(n, k); } } //cout << ans.val() << '\n'; ans *= mint(4).inv().pow(n); }else{ if (n % 2 == 1){ cout << 0 << '\n'; return 0; } mint tar = 0; for (ll k=0; k<=n; k++){ if ((k)%2 == 1) continue; if ((n-k)%2 == 1) continue; ans -= cmb(k, (k)/2) * cmb(n-k, (n-k)/2) * cmb(n, k); } ans += cmb(n, n/2) * mint(2).pow(n) * 2; //cout << ans.val() << '\n'; ans *= mint(4).inv().pow(n); } cout << ans.val() << '\n'; }