結果

問題 No.1120 Strange Teacher
ユーザー uni_pythonuni_python
提出日時 2020-07-31 23:20:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 1,000 ms
コード長 1,222 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 100,028 KB
最終ジャッジ日時 2023-09-21 02:50:37
合計ジャッジ時間 5,032 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,328 KB
testcase_01 AC 75 ms
71,448 KB
testcase_02 AC 78 ms
75,576 KB
testcase_03 AC 83 ms
76,152 KB
testcase_04 AC 116 ms
99,552 KB
testcase_05 AC 116 ms
99,596 KB
testcase_06 AC 116 ms
99,404 KB
testcase_07 AC 118 ms
99,768 KB
testcase_08 AC 116 ms
99,472 KB
testcase_09 AC 74 ms
71,136 KB
testcase_10 AC 113 ms
100,028 KB
testcase_11 AC 112 ms
99,608 KB
testcase_12 AC 112 ms
99,744 KB
testcase_13 AC 112 ms
99,456 KB
testcase_14 AC 114 ms
99,444 KB
testcase_15 AC 119 ms
99,908 KB
testcase_16 AC 115 ms
99,608 KB
testcase_17 AC 113 ms
99,612 KB
testcase_18 AC 74 ms
71,412 KB
testcase_19 AC 115 ms
98,032 KB
testcase_20 AC 74 ms
71,120 KB
testcase_21 AC 74 ms
71,328 KB
testcase_22 AC 73 ms
71,120 KB
testcase_23 AC 72 ms
71,224 KB
testcase_24 AC 115 ms
99,272 KB
testcase_25 AC 75 ms
71,324 KB
testcase_26 AC 76 ms
71,244 KB
testcase_27 AC 74 ms
71,396 KB
testcase_28 AC 74 ms
71,240 KB
testcase_29 AC 75 ms
71,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    B=LI()
    
    if N==2:
        a=A[0]-B[0]
        b=A[1]-B[1]
        if a==-b:
            print(abs(a))
        else:
            print(-1)
            
    else:
        diff=0
        M=0
        # 答え候補はすぐわかる
        for i in range(N):
            d=A[i]-B[i]
            diff+=d
            
        if diff%(N-2)!=0:
            print(-1)
        else:
            #全員-1して,誰かを+2,これがans回
            
            ans=diff//(N-2)
            for i in range(N):
                A[i]-=ans
            
            cnt=0
            for i in range(N):
                if B[i]-A[i]<0:
                    ans=-1
                    break
                elif (B[i]-A[i])%2!=0:
                    ans=-1
                    break
                else:
                    cnt+=(B[i]-A[i])//2
                    
            if cnt==ans:
                print(ans)
            else:
                print(-1)
                    
            
        


main()
0