結果
| 問題 |
No.1120 Strange Teacher
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-22 21:41:21 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 1,000 ms |
| コード長 | 537 bytes |
| コンパイル時間 | 2,004 ms |
| コンパイル使用メモリ | 194,976 KB |
| 最終ジャッジ日時 | 2025-01-12 02:25:44 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | int n; scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | rep(i,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
main.cpp:12:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | rep(i,n) scanf("%d",&b[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int n; scanf("%d",&n);
vector<int> a(n),b(n);
rep(i,n) scanf("%d",&a[i]);
rep(i,n) scanf("%d",&b[i]);
lint d=0;
rep(i,n) d+=a[i]-b[i];
if(n==2){
if(d==0){
printf("%d\n",abs(a[0]-b[0]));
}
else{
puts("-1");
}
return 0;
}
if(d<0 || d%(n-2)!=0) return puts("-1"),0;
lint k=d/(n-2);
rep(i,n) if(b[i]-a[i]+k<0 || (b[i]-a[i]+k)%2!=0) return puts("-1"),0;
printf("%lld\n",k);
return 0;
}