結果

問題 No.1120 Strange Teacher
ユーザー yuya1234yuya1234
提出日時 2020-07-22 22:09:29
言語 C++14
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |            ^~~~~

ソースコード

diff #

/**
*    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;
}
0