結果
問題 | No.1120 Strange Teacher |
ユーザー |
|
提出日時 | 2020-07-22 22:09:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,441 bytes |
コンパイル時間 | 1,635 ms |
コンパイル使用メモリ | 167,348 KB |
実行使用メモリ | 13,756 KB |
最終ジャッジ日時 | 2024-06-22 18:20:12 |
合計ジャッジ時間 | 4,523 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | WA * 4 TLE * 1 -- * 22 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:57:13: warning: 'idmax' may be used uninitialized [-Wmaybe-uninitialized] 57 | if(i==idmax)a[i]+=sum; | ^~~~~ main.cpp:42:12: note: 'idmax' was declared here 42 | int _max,idmax,_min,idmin; | ^~~~~
ソースコード
/*** author: yuya1234* created: 22.07.2020 21:25:31**/#include <bits/stdc++.h>using namespace std;typedef long long ll;#define REP(i,n) for(ll i=0;i<(ll)(n);i++)#define REPD(i,n) for(ll i=n-1;i>=0;i--)#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)#define SORT(x) sort(x.begin(),x.end())#define SORTD(x) sort(x.rbegin(),x.rend())#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );#define SZ(x) ll(x.size())#define MEMSET(v, h) memset((v), h, sizeof(v))template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }int gcd(int a,int b){return b?gcd(b,a%b):a;}int main() {cin.tie(0);ios_base::sync_with_stdio(false);int n;cin>>n;int a[n],b[n],s=0;REP(i,n)cin>>a[i];REP(i,n){cin>>b[i];s+=b[i];}int _max,idmax,_min,idmin;int ans=0;REP(ii,n){_max=0;_min=INT_MAX;REP(i,n){if(chmax(_max,b[i]-a[i]))idmax=i;if(chmin(_min,b[i]-a[i]))idmin=i;}if(_max==0 && _min==0)break;int sum=max(_max,abs(_min));REP(i,n){if(i==idmax)a[i]+=sum;else a[i]-=sum;}ans+=sum;int ss=0;REP(i,n)ss+=a[i];if(ss==s)break;if(ii==n-1){cout<<-1<<endl;return 0;}}cout<<ans<<endl;return 0;}