結果
問題 |
No.186 中華風 (Easy)
|
ユーザー |
![]() |
提出日時 | 2016-10-14 13:04:51 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 912 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-11-22 06:10:02 |
合計ジャッジ時間 | 2,042 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 14 |
ソースコード
def gcd(x, y): if y == 0: return x else: return gcd(y, x%y) def extgcd(a,b): if b == 1: return (0,1) else: t = extgcd(b,a%b) return (t[1], t[0]-a//b*t[1]) def solve(x0,y0,x1,y1): c = x0-x1 a = y0 b = -y1 if c < 0: a = -a b = -b sm0 = 1 sm1 = 1 if a < 0: sm0 = -1 if b < 0: sm1 = -1 g = gcd(sm0*a,sm1*b) # print(c) if c != 0: if c%g != 0: return (-1,-1) ps = extgcd(sm0*a//g,sm1*b//g) # print(ps) ps = (ps[0]*sm0*c//g,ps[1]*sm1*c//g) # ps[1] = ps[1]*sm1*c//g ho = sm1*b//g ge = ps[0] return (ho*y0, x0+y0*ge) else: return (y0*sm1*b//g, x0) if __name__ == '__main__': x = [] y = [] for i in range(3): a,b = map(int,input().split()) x.append(a) y.append(b) s1 = solve(x[0],y[0],x[1],y[1]) # print(s1) if s1[0] == -1: print(-1) exit() s2 = solve(s1[1],s1[0],x[2],y[2]) if s2[0] == -1: print(-1) exit() # print(s2) print(s2[1]%s2[0])