結果
問題 |
No.1120 Strange Teacher
|
ユーザー |
![]() |
提出日時 | 2020-07-22 22:23:49 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,114 bytes |
コンパイル時間 | 12,784 ms |
コンパイル使用メモリ | 402,900 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 19:00:26 |
合計ジャッジ時間 | 14,790 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 6 |
ソースコード
use std::io::Read; fn read<T: std::str::FromStr>() -> T { let token: String = std::io::stdin() .bytes() .map(|c| c.ok().unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().unwrap() } fn main() { let n: i32 = read(); let a: Vec<i32> = (0..n).map(|_| read()).collect(); let b: Vec<i32> = (0..n).map(|_| read()).collect(); let d = a.iter().sum::<i32>() - b.iter().sum::<i32>(); if n == 2 { if d == 0 { println!("{}", (a[0] - b[0]).abs()); } else { println!("-1"); } return; } if d < 0 || d % (n - 2) != 0 { println!("-1"); return; } let k = d / (n - 2); let a2: Vec<i32> = a.iter().map(|x| x - k).collect(); let mut m = 0; for (a, b) in a2.iter().zip(b.iter()) { if a > b || (b - a) % 2 != 0 { println!("-1"); return; } m += (b - a) / 2; } if m <= k { println!("{}", k); } else { println!("-1"); } }