結果
問題 | No.1120 Strange Teacher |
ユーザー |
|
提出日時 | 2020-07-22 21:44:38 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 28 ms / 1,000 ms |
コード長 | 990 bytes |
コンパイル時間 | 934 ms |
コンパイル使用メモリ | 132,908 KB |
実行使用メモリ | 10,800 KB |
最終ジャッジ日時 | 2024-06-22 07:45:24 |
合計ジャッジ時間 | 3,470 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.stdlib, std.datetime; void main() { auto N = readln.chomp.to!int; auto A = readln.split.map!(to!long).array; auto B = readln.split.map!(to!long).array; auto sa = A.sum; auto sb = B.sum; if (N == 2) { if (sa != sb) { writeln(-1); } else { writeln(abs(A.front - B.front)); } return; } if (sa < sb) { writeln(-1); return; } if ((sa - sb) % (N - 2) != 0) { writeln(-1); return; } auto cnt = (sa - sb) / (N - 2); A[] -= cnt; long cnt2 = 0; foreach (i, a; A) { if (A[i] > B[i] || (B[i] - A[i]) % 2 != 0) { writeln(-1); return; } cnt2 += (B[i] - A[i]) / 2; } writeln(cnt == cnt2 ? cnt : -1); }