結果
問題 | No.1120 Strange Teacher |
ユーザー | Lê Hoàng Ngô |
提出日時 | 2024-06-29 10:49:43 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 21 ms / 1,000 ms |
コード長 | 2,558 bytes |
コンパイル時間 | 1,426 ms |
コンパイル使用メモリ | 169,564 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-29 10:49:47 |
合計ジャッジ時間 | 2,894 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 19 ms
5,376 KB |
testcase_05 | AC | 19 ms
5,376 KB |
testcase_06 | AC | 19 ms
5,376 KB |
testcase_07 | AC | 19 ms
5,376 KB |
testcase_08 | AC | 19 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 18 ms
5,376 KB |
testcase_11 | AC | 18 ms
5,376 KB |
testcase_12 | AC | 18 ms
5,376 KB |
testcase_13 | AC | 19 ms
5,376 KB |
testcase_14 | AC | 18 ms
5,376 KB |
testcase_15 | AC | 18 ms
5,376 KB |
testcase_16 | AC | 18 ms
5,376 KB |
testcase_17 | AC | 19 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 21 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 17 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 1 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
testcase_28 | AC | 2 ms
5,376 KB |
testcase_29 | AC | 1 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep_r(i,a,b) for(int i=a;i>=b;i--) #define each(a,x) for (auto& x : a) using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; #define sz(x) int(x.size()) #define so(x) sort(all(x)) #define so_r(x) sort(all(x),greater<int>()) #define lb lower_bound #define ub upper_bound const char nl = '\n'; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int bit_cnt(int x){ return __builtin_popcount(x); } ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} const int MOD = 998244353; const int N = 5e5 + 5; const ll INF = 1e16; // https://yukicoder.me/problems/no/1120 // Brief: N students, real points are A1, A2, ... AN // but teacher wants to change to B1, B2, ... BN // in each operation, teacher can increase 1 point for one student but decrease all other students 1 point // find out minimum operations to achieve that, if impossible print -1 int n; int a[N], b[N]; void solve(){ cin >> n; rep(i,1,n) cin >> a[i]; rep(i,1,n) cin >> b[i]; ll dif = 0; rep(i,1,n) dif+=a[i]-b[i]; // each operation will make total points decrease n-2 // => dif % (n-2) == 0 // and dif > 0 // special case is n == 2 // => dif == 0 if (n == 2){ if (dif != 0) cout << -1 << nl; else cout << abs(a[1] - b[1]) << nl; return; } if (dif % (n-2) != 0 || dif < 0){ cout << -1 << nl; return; } ll operations = dif / (n-2); // number of operations will be used // add[i] is the number of operations teacher use for increasing point for student[i] // b[i] = a[i] - operations + 2 * add[i] vl add(n+1); rep(i,1,n){ ll tmp = b[i] - a[i] + operations; if (tmp % 2 == 1 || tmp < 0) { cout << -1 << nl; return; } add[i] = tmp / 2; } ll tot = operations; rep(i,1,n){ tot -= add[i]; } if (tot != 0) { cout << -1 << nl; } else { cout << operations << nl; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--){ solve(); } }