結果
問題 | No.2406 Difference of Coordinate Squared |
ユーザー | milanis48663220 |
提出日時 | 2023-08-04 23:17:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 3,187 bytes |
コンパイル時間 | 1,108 ms |
コンパイル使用メモリ | 127,028 KB |
実行使用メモリ | 27,008 KB |
最終ジャッジ日時 | 2024-05-05 01:41:44 |
合計ジャッジ時間 | 7,232 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 77 ms
26,880 KB |
testcase_01 | AC | 87 ms
27,008 KB |
testcase_02 | AC | 86 ms
26,880 KB |
testcase_03 | AC | 90 ms
26,752 KB |
testcase_04 | AC | 112 ms
26,880 KB |
testcase_05 | AC | 84 ms
26,880 KB |
testcase_06 | AC | 82 ms
26,752 KB |
testcase_07 | AC | 80 ms
26,880 KB |
testcase_08 | AC | 80 ms
26,752 KB |
testcase_09 | AC | 141 ms
26,752 KB |
testcase_10 | AC | 92 ms
26,880 KB |
testcase_11 | AC | 87 ms
26,880 KB |
testcase_12 | AC | 90 ms
26,880 KB |
testcase_13 | AC | 168 ms
26,880 KB |
testcase_14 | AC | 87 ms
26,752 KB |
testcase_15 | AC | 86 ms
26,752 KB |
testcase_16 | AC | 93 ms
26,880 KB |
testcase_17 | AC | 77 ms
26,752 KB |
testcase_18 | AC | 79 ms
26,880 KB |
testcase_19 | AC | 87 ms
26,880 KB |
testcase_20 | AC | 93 ms
26,752 KB |
testcase_21 | AC | 85 ms
26,880 KB |
testcase_22 | AC | 87 ms
26,880 KB |
testcase_23 | AC | 122 ms
26,880 KB |
testcase_24 | AC | 89 ms
26,880 KB |
testcase_25 | AC | 80 ms
26,752 KB |
testcase_26 | AC | 77 ms
26,880 KB |
testcase_27 | AC | 74 ms
26,752 KB |
testcase_28 | AC | 75 ms
26,880 KB |
testcase_29 | AC | 76 ms
26,752 KB |
testcase_30 | AC | 74 ms
26,880 KB |
testcase_31 | AC | 79 ms
26,752 KB |
testcase_32 | AC | 82 ms
26,752 KB |
testcase_33 | AC | 79 ms
26,880 KB |
testcase_34 | AC | 78 ms
26,752 KB |
testcase_35 | AC | 77 ms
26,880 KB |
testcase_36 | AC | 81 ms
26,752 KB |
testcase_37 | AC | 75 ms
26,880 KB |
testcase_38 | AC | 75 ms
26,752 KB |
testcase_39 | AC | 75 ms
26,880 KB |
testcase_40 | AC | 77 ms
26,880 KB |
testcase_41 | AC | 76 ms
26,880 KB |
testcase_42 | AC | 80 ms
26,752 KB |
testcase_43 | AC | 81 ms
27,008 KB |
testcase_44 | AC | 77 ms
26,880 KB |
testcase_45 | AC | 77 ms
26,880 KB |
testcase_46 | AC | 77 ms
26,752 KB |
testcase_47 | AC | 79 ms
26,752 KB |
testcase_48 | AC | 76 ms
26,880 KB |
testcase_49 | AC | 76 ms
26,880 KB |
testcase_50 | AC | 89 ms
26,880 KB |
testcase_51 | AC | 81 ms
26,880 KB |
testcase_52 | AC | 78 ms
26,880 KB |
testcase_53 | AC | 79 ms
26,752 KB |
testcase_54 | AC | 78 ms
26,880 KB |
testcase_55 | AC | 76 ms
26,752 KB |
testcase_56 | AC | 77 ms
26,880 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #include <atcoder/modint> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using mint = atcoder::modint998244353; ostream& operator<<(ostream& os, const mint& m){ os << m.val(); return os; } #define N_MAX 2000002 mint inv[N_MAX],fac[N_MAX],finv[N_MAX]; void init(){ const ll MOD = mint::mod(); fac[0]=1;fac[1]=1; finv[0]=1;finv[1]=1; inv[1]=1; for(int i=2;i<N_MAX;i++){ inv[i]=mint(MOD)-inv[MOD%i]*(MOD/i); fac[i]=fac[i-1]*(ll) i; finv[i]=finv[i-1]*inv[i]; } } mint comb(ll n, ll r){ if(n < r){ return mint(0); }else{ return fac[n]*finv[r]*finv[n-r]; } } using P = pair<ll, ll>; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; init(); ll n, m; cin >> n >> m; m = abs(m); if(m == 0){ mint ans = 0; if(n%2 == 0){ ans += comb(n, n/2)*mint(2).pow(n)*2; for(int i = 0; i <= n; i+=2){ int j = n-i; ans -= comb(n, i)*comb(n-i, j)*comb(i, i/2)*comb(j, j/2); } } ans /= mint(4).pow(n); cout << ans << endl; return 0; } ll sum = 0; mint ans = 0; auto f = [&](ll x, ll y){ mint ans = 0; for(int i = x; i <= n; i++){ int j = n-i; if(j < y) continue; if(i%2 != x%2) continue; if(j%2 != y%2) continue; ans += comb(n, i)*comb(i, (i-x)/2)*comb(j, (j-y)/2); } return ans; }; set<P> st; for(ll X = 1; X*X <= m; X++){ if(m%X != 0) continue; ll Y = m/X; if(X%2 != Y%2) continue; ll x = abs(X-Y)/2; ll y = abs(X+Y)/2; if(x+y > n) continue; sum++; st.insert({x, y}); st.insert({y, x}); } for(auto [x, y]: st) { if(x*x - y*y != m) continue; mint p = f(x, y); if(x != 0) p *= 2; if(y != 0) p *= 2; ans += p; } ans /= mint(4).pow(n); cout << ans << endl; }