結果

問題 No.1627 三角形の成立
ユーザー googol_S0googol_S0
提出日時 2021-07-23 22:15:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 952 bytes
コンパイル時間 307 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 94,784 KB
最終ジャッジ日時 2023-09-25 22:19:44
合計ジャッジ時間 4,759 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
87,680 KB
testcase_01 AC 95 ms
87,376 KB
testcase_02 AC 97 ms
87,460 KB
testcase_03 AC 98 ms
87,460 KB
testcase_04 AC 96 ms
87,700 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=10**9+7
def cmb(n,r):
  if r<0 or r>n:
    return 0
  return (g1[n]*g2[r]*g2[n-r])%mod
 
N=500000
g1=[1]*(N+3)
for i in range(2,N+3):
  g1[i]=g1[i-1]*i%mod
g2=[0]*len(g1)
g2[-1]=pow(g1[-1],mod-2,mod)
for i in range(N+1,-1,-1):
  g2[i]=g2[i+1]*(i+1)%mod
inv=[0]*(N+3)
for i in range(1,N+3):
  inv[i]=g2[i]*g1[i-1]%mod
N,M=map(int,input().split())
X=[0]*(N+M+2)
Y=[0]*(N+M+2)
Y[N]+=M
for i in range(-N,N+1):
  if i==0:
    Y[M]+=N
    continue
  i=abs(i)
  y=(N-1)//i+1
  if y>=M:
    z=(M-1)*i
    Y[M]+=N-z
    X[0]+=i*2
    X[M]-=i*2
  else:
    z=(y-1)*i
    Y[y]+=(M-y+1)*(N-z)
    X[0]+=i*2
    X[y]-=i*2
N,M=M,N
for i in range(-N,N+1):
  if abs(i)<=1:
    continue
  i=abs(i)
  y=(N-1)//i+1
  if y>=M:
    z=(M-1)*i
    Y[M]+=N-z
    X[0]+=i*2
    X[M]-=i*2
  else:
    z=(y-1)*i
    Y[y]+=(M-y+1)*(N-z)
    X[0]+=i*2
    X[y]-=i*2
L=N*M
ANS=L*(L-1)*(L-2)//6
for i in range(N+M):
  X[i+1]+=X[i]
  ANS-=cmb(i+1,3)*(X[i+1]+Y[i+1])
print(ANS%mod)
0