結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2021-05-01 16:18:46 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,262 bytes |
| コンパイル時間 | 946 ms |
| コンパイル使用メモリ | 113,672 KB |
| 実行使用メモリ | 44,848 KB |
| 最終ジャッジ日時 | 2024-07-20 00:24:52 |
| 合計ジャッジ時間 | 4,976 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 WA * 11 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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 % (n - 2L) != 0) { Console.WriteLine(-1); return; }
else count += w / (n - 2L);
}
}
if (count == t) Console.WriteLine(t);
}
}
bluemegane