結果

問題 No.999 てん vs. ほむ
ユーザー i_am_nicolen_22i_am_nicolen_22
提出日時 2020-02-28 21:53:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,992 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 164,236 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 18:23:30
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 55 ms
6,940 KB
testcase_18 AC 54 ms
6,944 KB
testcase_19 AC 55 ms
6,944 KB
testcase_20 AC 55 ms
6,944 KB
testcase_21 AC 81 ms
6,944 KB
testcase_22 AC 80 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
   int n;
   cin>>n;
   vector<int>a(2*n);
   REP(i,2*n) cin>>a[i];
   if(n==1){
       cout<<abs(a[0] - a[1])<<endl;
       return 0;
   }
   int cnta=0,cntb=0;
   int index1 = 0,index2 = 2*n-1;
   int cnt=0;
   while(cnt<n){
       if(a[index1] -  a[index1+1] >= a[index2] - a[index2-1]){
           cnta+=a[index1];
           cntb+=a[index1+1];
           index1+=2;
       }
       else{
           cnta+=a[index2];
           cntb+=a[index2-1];
           index2-=2;
       }
      // cerr<<cnta<<cntb<<endl;
       cnt++;
   }
   cout<<cnta-cntb<<endl;
    return 0;
}
0