結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー tossytossy
提出日時 2017-05-07 13:51:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 197 ms / 4,000 ms
コード長 2,619 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 181,064 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2023-08-16 03:09:16
合計ジャッジ時間 4,797 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 197 ms
10,460 KB
testcase_30 AC 169 ms
10,120 KB
testcase_31 AC 128 ms
9,932 KB
testcase_32 AC 119 ms
10,400 KB
testcase_33 AC 80 ms
6,652 KB
testcase_34 AC 89 ms
5,856 KB
testcase_35 AC 125 ms
10,432 KB
testcase_36 AC 129 ms
10,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 12345678912345678LL

template<typename T>
class SegTree {
public:
  int n;
  vector<T> segMax, segAdd;
  vector<int> segIdx;
  void _add(int a, int b, T x, int k, int l, int r){
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){segAdd[k]+=x; return;}
    int cl = k*2+1, cr = k*2+2;
    _add(a,b,x,cl,l,(l+r)/2);
    _add(a,b,x,cr,(l+r)/2,r);
    T vl = segMax[cl]+segAdd[cl];
    T vr = segMax[cr]+segAdd[cr];
    if(vl > vr){
      segMax[k] = vl;
      segIdx[k] = segIdx[cl];
    } else {
      segMax[k] = vr;
      segIdx[k] = segIdx[cr];
    }
  }
  pair<T, int> _max(int a, int b, int k, int l, int r){ // <val, idx> (tree上でのidx)
    if(r<=a || b<=l) return mp(-INF, -100);
    if(a<=l && r<=b) return mp(segMax[k]+segAdd[k], segIdx[k]);
    pair<T,int> vl = _max(a,b,k*2+1,l,(l+r)/2);
    pair<T,int> vr = _max(a,b,k*2+2,(l+r)/2,r);
    if(vl.fi > vr.fi) return mp(vl.fi+segAdd[k], vl.se);
    else return mp(vr.fi+segAdd[k], vr.se);
  }
  SegTree(int n_){
    n=1;
    while(n<n_) n*=2;
    segMax.resize(2*n-1);
    fill(all(segMax), 0);
    segAdd.resize(2*n-1);
    fill(all(segAdd), 0);
    segIdx.resize(2*n-1);
    repl(i,n-1,2*n-1) segIdx[i] = i;
    for(int i=n-2; i>=0; i--) segIdx[i] = segIdx[2*i+1];
  }
  inline void add(int a, int b, T x){ _add(a,b,x,0,0,n);} //add x in [a,b)
  inline pair<T,int> getMax(int a,int b){return _max(a,b,0,0,n);}
};


int main(){
  long n,w,h;
  cin>>n>>w>>h;

  SegTree<long> st(w);

  vector<long> a(n),b(n),x(n);
  rep(i,n) cin>>a[i]>>b[i]>>x[i];
  rep(i,n) x[i]--;

  int p[2] = {0,0};
  rep(i,n){
    st.add(x[i], x[i]+a[i], b[i]);
    while(true){
      auto val = st.getMax(x[i],x[i]+a[i]);
//      dbg(mp(val.fi, val.se - (st.n-1)));
      if(val.fi<h) break;
      p[i%2]++;
      int idx = val.se - (st.n-1);
      st.add(idx, idx+1, -INF);
    }
//    dbg(mp(p[0],p[1]));
    if(p[0]+p[1]>=w) break;
  }

  if(p[0]>p[1]) cout << "A" << endl;
  else if(p[0]==p[1]) cout << "DRAW" << endl;
  else cout << "B" << endl;

  return 0;
}
0