結果
問題 | No.2406 Difference of Coordinate Squared |
ユーザー | chineristAC |
提出日時 | 2023-08-04 22:45:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 178 ms / 2,000 ms |
コード長 | 2,093 bytes |
コンパイル時間 | 255 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 100,096 KB |
最終ジャッジ日時 | 2024-05-05 01:40:42 |
合計ジャッジ時間 | 8,912 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
82,560 KB |
testcase_01 | AC | 125 ms
83,200 KB |
testcase_02 | AC | 178 ms
100,096 KB |
testcase_03 | AC | 115 ms
82,432 KB |
testcase_04 | AC | 173 ms
95,872 KB |
testcase_05 | AC | 148 ms
89,600 KB |
testcase_06 | AC | 133 ms
83,328 KB |
testcase_07 | AC | 117 ms
83,456 KB |
testcase_08 | AC | 135 ms
83,072 KB |
testcase_09 | AC | 129 ms
87,808 KB |
testcase_10 | AC | 127 ms
83,328 KB |
testcase_11 | AC | 133 ms
82,944 KB |
testcase_12 | AC | 137 ms
83,072 KB |
testcase_13 | AC | 128 ms
88,064 KB |
testcase_14 | AC | 123 ms
83,456 KB |
testcase_15 | AC | 121 ms
83,328 KB |
testcase_16 | AC | 127 ms
83,456 KB |
testcase_17 | AC | 119 ms
82,432 KB |
testcase_18 | AC | 124 ms
82,176 KB |
testcase_19 | AC | 125 ms
82,816 KB |
testcase_20 | AC | 123 ms
83,328 KB |
testcase_21 | AC | 123 ms
82,816 KB |
testcase_22 | AC | 119 ms
82,304 KB |
testcase_23 | AC | 121 ms
83,380 KB |
testcase_24 | AC | 121 ms
83,584 KB |
testcase_25 | AC | 119 ms
82,048 KB |
testcase_26 | AC | 122 ms
82,432 KB |
testcase_27 | AC | 119 ms
82,560 KB |
testcase_28 | AC | 124 ms
82,816 KB |
testcase_29 | AC | 111 ms
82,432 KB |
testcase_30 | AC | 126 ms
82,432 KB |
testcase_31 | AC | 122 ms
82,176 KB |
testcase_32 | AC | 126 ms
82,688 KB |
testcase_33 | AC | 113 ms
82,560 KB |
testcase_34 | AC | 125 ms
82,304 KB |
testcase_35 | AC | 119 ms
82,432 KB |
testcase_36 | AC | 120 ms
82,176 KB |
testcase_37 | AC | 112 ms
82,304 KB |
testcase_38 | AC | 116 ms
82,432 KB |
testcase_39 | AC | 112 ms
82,560 KB |
testcase_40 | AC | 125 ms
82,432 KB |
testcase_41 | AC | 118 ms
82,432 KB |
testcase_42 | AC | 118 ms
82,048 KB |
testcase_43 | AC | 120 ms
82,648 KB |
testcase_44 | AC | 119 ms
82,560 KB |
testcase_45 | AC | 114 ms
82,432 KB |
testcase_46 | AC | 122 ms
82,432 KB |
testcase_47 | AC | 121 ms
82,688 KB |
testcase_48 | AC | 126 ms
82,176 KB |
testcase_49 | AC | 115 ms
82,688 KB |
testcase_50 | AC | 126 ms
82,432 KB |
testcase_51 | AC | 109 ms
82,816 KB |
testcase_52 | AC | 128 ms
82,560 KB |
testcase_53 | AC | 117 ms
82,328 KB |
testcase_54 | AC | 126 ms
82,432 KB |
testcase_55 | AC | 110 ms
82,560 KB |
testcase_56 | AC | 126 ms
82,560 KB |
ソースコード
import sys input = lambda :sys.stdin.readline().rstrip() def cmb(n, r, mod): if ( r<0 or r>n ): return 0 return (g1[n] * g2[r] % mod) * g2[n-r] % mod mod = 998244353 N = 10**6 + 10 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 N,M = map(int,input().split()) if M == 0: res = 0 """ X+Y = 0 """ if N & 1 == 0: res += cmb(N,N//2,mod) * pow(inverse[2],N,mod) * 2 % mod res %= mod res -= cmb(N,N//2,mod) * cmb(N,N//2,mod) * pow(inverse[2],2*N,mod) % mod res %= mod print(res) else: divisors = [] for d in range(1,abs(M)+1): if d*d > abs(M): break if M % d == 0: divisors.append(d) divisors.append(-d) if abs(M)//d != d: divisors.append(M//d) divisors.append(-M//d) divisors.sort() res = 0 for d in divisors: p = d m = M // d tmp = 1 if (N+p) & 1 == 0 and 0 <= (N+p)//2 <= N: tmp *= cmb(N,(N+p)//2,mod) tmp %= mod else: tmp = 0 if (N+m) & 1 == 0 and 0 <= (N+m)//2 <= N: tmp *= cmb(N,(N+m)//2,mod) tmp %= mod else: tmp = 0 res += tmp res %= mod res *= pow(inverse[4],N,mod) res %= mod print(res) exit() dp = [[0]*(2*N+1) for i in range(2*N+1)] dp[0][0] = 1 for _ in range(N): ndp = [[0]*(2*N+1) for i in range(2*N+1)] for i in range(-N,N+1): for j in range(-N,N+1): if not dp[i][j]: continue for ni,nj in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]: ndp[ni][nj] += dp[i][j] * inverse[4] % mod ndp[ni][nj] %= mod dp = ndp check = 0 for i in range(-N,N+1): for j in range(-N,N+1): if i*i-j*j == M: check += dp[i][j] check %= mod print(check)