結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー akakimidoriakakimidori
提出日時 2018-12-05 19:11:43
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 79 ms / 4,000 ms
コード長 1,898 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 30,680 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 03:10:29
合計ジャッジ時間 2,120 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 0 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 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 0 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 0 ms
4,384 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 0 ms
4,384 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 0 ms
4,384 KB
testcase_20 AC 0 ms
4,384 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 0 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 0 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 79 ms
4,384 KB
testcase_30 AC 69 ms
4,384 KB
testcase_31 AC 43 ms
4,380 KB
testcase_32 AC 67 ms
4,384 KB
testcase_33 AC 7 ms
4,380 KB
testcase_34 AC 15 ms
4,380 KB
testcase_35 AC 31 ms
4,384 KB
testcase_36 AC 32 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

typedef struct RMQandRAQ{
  int64 *add;
  int64 *max;
  int size,bit;
} segTree;

segTree* newRMQandRAQ(const int n){
  int k=0;
  while((1<<k)<n) k++;
  int size=1<<k;
  segTree *s=(segTree *)malloc(sizeof(segTree));
  s->add=(int64 *)calloc(2*size,sizeof(int64));
  s->max=(int64 *)calloc(2*size,sizeof(int64));
  s->size=size;
  s->bit=k;
  return s;
}

inline int64 max(int64 a,int64 b){
  return a>b?a:b;
}

inline int64 calcMax(segTree *s,int k){
  return s->add[k]+s->max[k];
}

void propagate(segTree *s,int k){
  if(s->add[k]==0) return;
  s->add[2*k  ]+=s->add[k];
  s->add[2*k+1]+=s->add[k];
  s->add[k]=0;
  s->max[k]=max(calcMax(s,2*k),calcMax(s,2*k+1));
  return;
}

void add(segTree *s,int l,int r,int64 v){
  l+=s->size;
  r+=s->size-1;
  for(int i=s->bit;i>0;i--){
    propagate(s,l>>i);
    propagate(s,r>>i);
  }
  for(int x=l,y=r+1;x<y;x>>=1,y>>=1){
    if(x&1) s->add[x++]+=v;
    if(y&1) s->add[--y]+=v;
  }
  l>>=1;
  r>>=1;
  while(l>=1){
    s->max[l]=max(calcMax(s,2*l),calcMax(s,2*l+1));
    s->max[r]=max(calcMax(s,2*r),calcMax(s,2*r+1));
    l>>=1;
    r>>=1;
  }
}

int search_sub(segTree *s,int k,int l,int r,int64 h){
  if(calcMax(s,k)<h) return 0;
  if(k>=s->size){
    add(s,k-s->size,k-s->size+1,-1000000000000000000LL);
    return 1;
  }
  propagate(s,k);
  int m=(l+r)/2;
  int res=search_sub(s,2*k,l,m,h)+search_sub(s,2*k+1,m,r,h);
  return res;
}

int search(segTree *s,int64 h){
  return search_sub(s,1,0,s->size,h);
}

void run(void){
  int n,w;
  int64 h;
  scanf("%d%d%lld",&n,&w,&h);
  segTree *s=newRMQandRAQ(w);
  int cnt[2]={0,0};
  int i;
  for(i=0;i<n && cnt[0]+cnt[1]<w;i++){
    int a,b,x;
    scanf("%d%d%d",&a,&b,&x);
    add(s,x-1,x-1+a,b);
    cnt[i&1]+=search(s,h);
  }
  printf("%s\n",cnt[0]==cnt[1]?"DRAW":cnt[0]>cnt[1]?"A":"B");
}

int main(void){
  run();
  return 0;
}
0