結果

問題 No.1120 Strange Teacher
ユーザー bluemeganebluemegane
提出日時 2021-05-01 16:23:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 1,250 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 65,784 KB
実行使用メモリ 43,436 KB
最終ジャッジ日時 2023-09-27 06:16:58
合計ジャッジ時間 6,645 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,580 KB
testcase_01 AC 64 ms
21,512 KB
testcase_02 AC 69 ms
21,920 KB
testcase_03 AC 75 ms
22,848 KB
testcase_04 AC 138 ms
41,340 KB
testcase_05 AC 138 ms
37,320 KB
testcase_06 AC 137 ms
39,176 KB
testcase_07 AC 138 ms
39,340 KB
testcase_08 AC 135 ms
39,228 KB
testcase_09 AC 63 ms
21,556 KB
testcase_10 AC 135 ms
41,416 KB
testcase_11 AC 137 ms
41,424 KB
testcase_12 AC 135 ms
43,436 KB
testcase_13 AC 137 ms
37,328 KB
testcase_14 AC 137 ms
39,368 KB
testcase_15 AC 139 ms
41,532 KB
testcase_16 AC 139 ms
39,312 KB
testcase_17 AC 137 ms
39,256 KB
testcase_18 AC 62 ms
23,572 KB
testcase_19 AC 140 ms
42,220 KB
testcase_20 AC 62 ms
21,644 KB
testcase_21 AC 63 ms
21,516 KB
testcase_22 AC 62 ms
21,552 KB
testcase_23 AC 61 ms
23,612 KB
testcase_24 AC 133 ms
40,292 KB
testcase_25 AC 64 ms
23,516 KB
testcase_26 AC 62 ms
23,628 KB
testcase_27 AC 61 ms
23,608 KB
testcase_28 AC 63 ms
21,596 KB
testcase_29 AC 61 ms
21,412 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.Sum() != b.Sum()) { 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++) a[i] -= t;
        var count = 0L;
        for (int i = 0; i < n; i++)
        {
            var w = b[i] - a[i];
            if (w < 0) { Console.WriteLine(-1); return; }
            if (w > 0)
            {
                if (w % 2L != 0) { Console.WriteLine(-1); return; }
                else count += w / 2L;
            }
        }
        if (count == t) Console.WriteLine(t);
    }
}
0