結果

問題 No.1120 Strange Teacher
ユーザー bluemeganebluemegane
提出日時 2021-05-01 16:30:45
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 130 ms / 1,000 ms
コード長 1,137 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 70,200 KB
実行使用メモリ 41,428 KB
最終ジャッジ日時 2023-09-27 06:24:10
合計ジャッジ時間 5,649 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
21,568 KB
testcase_01 AC 59 ms
23,508 KB
testcase_02 AC 64 ms
19,764 KB
testcase_03 AC 70 ms
22,792 KB
testcase_04 AC 128 ms
41,240 KB
testcase_05 AC 130 ms
41,232 KB
testcase_06 AC 124 ms
39,144 KB
testcase_07 AC 119 ms
37,244 KB
testcase_08 AC 126 ms
41,200 KB
testcase_09 AC 56 ms
23,460 KB
testcase_10 AC 120 ms
39,388 KB
testcase_11 AC 124 ms
37,304 KB
testcase_12 AC 122 ms
41,304 KB
testcase_13 AC 123 ms
41,428 KB
testcase_14 AC 122 ms
41,368 KB
testcase_15 AC 120 ms
41,412 KB
testcase_16 AC 125 ms
39,152 KB
testcase_17 AC 124 ms
39,204 KB
testcase_18 AC 57 ms
23,488 KB
testcase_19 AC 125 ms
40,196 KB
testcase_20 AC 54 ms
18,904 KB
testcase_21 AC 54 ms
22,796 KB
testcase_22 AC 55 ms
21,428 KB
testcase_23 AC 56 ms
23,524 KB
testcase_24 AC 119 ms
40,132 KB
testcase_25 AC 55 ms
22,800 KB
testcase_26 AC 56 ms
21,584 KB
testcase_27 AC 57 ms
23,540 KB
testcase_28 AC 54 ms
23,392 KB
testcase_29 AC 58 ms
21,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Linq;
using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, long.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line, long.Parse);
        if (n == 2) getAns2(n, a, b);
        else getAns3(n, a, b);
    }
    static void getAns2(int n, long[] a, long[] b)
    {
        if (a[0] + a[1] != b[0] + b[1]) { Console.WriteLine(-1); return; }
        Console.WriteLine(Abs(a[0] - b[0]));
    }
    static void getAns3(int n, long[] a, long[] b)
    {
        var d = a.Sum() - b.Sum();
        if (d % (n - 2L) != 0) { Console.WriteLine(-1); return; }
        var t = d / (n - 2L);
        for (int i = 0; i < n; i++)
        {
            var w = b[i] - a[i] + t;
            if (w < 0) { Console.WriteLine(-1); return; }
            if (w > 0)
            {
                if (w % 2L != 0) { Console.WriteLine(-1); return; }
            }
        }
        Console.WriteLine(t);
    }
}
0