結果

問題 No.973 余興
ユーザー LayCurseLayCurse
提出日時 2020-01-19 05:31:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,723 ms / 4,000 ms
コード長 4,308 bytes
コンパイル時間 2,529 ms
コンパイル使用メモリ 209,672 KB
実行使用メモリ 199,216 KB
最終ジャッジ日時 2023-09-15 19:50:28
合計ジャッジ時間 53,951 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,615 ms
198,940 KB
testcase_01 AC 1,580 ms
198,992 KB
testcase_02 AC 1,723 ms
199,012 KB
testcase_03 AC 1,583 ms
198,760 KB
testcase_04 AC 1,600 ms
199,144 KB
testcase_05 AC 1,551 ms
199,128 KB
testcase_06 AC 1,579 ms
198,972 KB
testcase_07 AC 1,582 ms
198,704 KB
testcase_08 AC 1,620 ms
198,116 KB
testcase_09 AC 1,619 ms
199,076 KB
testcase_10 AC 1,502 ms
191,352 KB
testcase_11 AC 442 ms
73,672 KB
testcase_12 AC 420 ms
73,712 KB
testcase_13 AC 435 ms
73,280 KB
testcase_14 AC 424 ms
73,248 KB
testcase_15 AC 41 ms
11,308 KB
testcase_16 AC 43 ms
11,420 KB
testcase_17 AC 25 ms
8,408 KB
testcase_18 AC 32 ms
9,808 KB
testcase_19 AC 33 ms
9,672 KB
testcase_20 AC 25 ms
8,340 KB
testcase_21 AC 41 ms
11,156 KB
testcase_22 AC 41 ms
11,256 KB
testcase_23 AC 33 ms
9,792 KB
testcase_24 AC 33 ms
9,732 KB
testcase_25 AC 15 ms
6,424 KB
testcase_26 AC 24 ms
8,112 KB
testcase_27 AC 48 ms
12,540 KB
testcase_28 AC 32 ms
9,744 KB
testcase_29 AC 32 ms
9,724 KB
testcase_30 AC 1,397 ms
198,980 KB
testcase_31 AC 1,399 ms
199,080 KB
testcase_32 AC 1,397 ms
199,016 KB
testcase_33 AC 1,424 ms
198,812 KB
testcase_34 AC 1,431 ms
198,108 KB
testcase_35 AC 1,424 ms
199,060 KB
testcase_36 AC 1,346 ms
193,772 KB
testcase_37 AC 1,401 ms
193,828 KB
testcase_38 AC 1,411 ms
198,376 KB
testcase_39 AC 1,409 ms
198,612 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 1,384 ms
199,152 KB
testcase_47 AC 1,404 ms
199,004 KB
testcase_48 AC 1,384 ms
199,216 KB
testcase_49 AC 1,281 ms
181,840 KB
testcase_50 AC 1,461 ms
197,680 KB
testcase_51 AC 1,392 ms
198,932 KB
testcase_52 AC 1,381 ms
199,056 KB
testcase_53 AC 1,353 ms
195,724 KB
testcase_54 AC 1,381 ms
198,992 KB
testcase_55 AC 1,412 ms
199,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
template<class T> struct fenwick{
  int size;
  int memory;
  T *data;
  void malloc(int mem);
  void walloc(int mem, void **workMemory = &wmem);
  void free(void);
  void init(int N);
  void add(int k, T val);
  T get(int k);
  T range(int a, int b);
  int kth(T k);
}
;
int N;
int X;
int A[5000];
int lf[5000];
int rg[5000];
fenwick<int> dp1[5000];
fenwick<int> dp2[5000];
int main(){
  wmem = memarr;
  int i;
  int j;
  int k;
  int len;
  int ok;
  rd(N);
  rd(X);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    j = i;
    k = A[i];
    while(j-1 >= 0 && k + A[j-1] <= X){
      k += A[--j];
    }
    lf[i] = j;
    j = i;
    k = A[i];
    while(j+1 < N  && k + A[j+1] <= X){
      k += A[++j];
    }
    rg[i] = j;
  }
  for(i=(0);i<(N);i++){
    dp1[i].malloc(N);
    dp1[i].init(N);
  }
  for(i=(0);i<(N);i++){
    dp2[i].malloc(N);
    dp2[i].init(N);
  }
  for(len=(1);len<(N+1);len++){
    for(i=(0);i<(N-len+1);i++){
      j = i + len - 1;
      ok = 0;
      if(len > 1 && dp1[i].range(max_L(i, lf[j]-1), j-1)){
        ok++;
      }
      if(len > 1 && dp2[j].range(i+1,min_L(j, rg[i]+1))){
        ok++;
      }
      if(ok==0){
        dp1[i].add(j,1);
        dp2[j].add(i,1);
      }
    }
  }
  k = dp1[0].range(N-1,N-1);
  if(k){
    wt_L("B");
    wt_L('\n');
  }
  else{
    wt_L("A");
    wt_L('\n');
  }
  return 0;
}
template<class T> void fenwick<T>::malloc(int mem){
  memory = mem;
  data = (T*)std::malloc(sizeof(T)*mem);
}
template<class T> void fenwick<T>::walloc(int mem, void **workMemory /* = &wmem*/){
  memory = mem;
  walloc1d(&data, mem, workMemory);
}
template<class T> void fenwick<T>::free(void){
  memory = 0;
  free(data);
}
template<class T> void fenwick<T>::init(int N){
  size = N;
  memset(data,0,sizeof(T)*N);
}
template<class T> void fenwick<T>::add(int k, T val){
  while(k < size){
    data[k] += val;
    k |= k+1;
  }
}
template<class T> T fenwick<T>::get(int k){
  T res = 0;
  while(k>=0){
    res += data[k];
    k = (k&(k+1))-1;
  }
  return res;
}
template<class T> T fenwick<T>::range(int a, int b){
  if(b==-1){
    b=size-1;
  }
  return get(b) - get(a-1);
}
template<class T> int fenwick<T>::kth(T k){
  int i=0;
  int j=size;
  int c;
  T v;
  while(i<j){
    c = (i+j)/2;
    v = get(c);
    if(v <= k){
      i=c+1;
    }
    else{
      j=c;
    }
  }
  return i==size?-1:i;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, X, A[5000];
// 
// int lf[5000], rg[5000];
// fenwick<int> dp1[5000];
// fenwick<int> dp2[5000];
// 
// {
//   int i, j, k, len, ok;
//   rd(N,X,A(N));
// 
//   rep(i,N){
//     j = i; k = A[i];
//     while(j-1 >= 0 && k + A[j-1] <= X) k += A[--j];
//     lf[i] = j;
// 
//     j = i; k = A[i];
//     while(j+1 < N  && k + A[j+1] <= X) k += A[++j];
//     rg[i] = j;
//   }
// 
//   rep(i,N) dp1[i].malloc(N), dp1[i].init(N);
//   rep(i,N) dp2[i].malloc(N), dp2[i].init(N);
// 
//   rep(len,1,N+1) rep(i,N-len+1){
//     j = i + len - 1;
//     ok = 0;
//     if(len > 1 && dp1[i].range(max(i,lf[j]-1), j-1)) ok++;
//     if(len > 1 && dp2[j].range(i+1,min(j,rg[i]+1))) ok++;
//     if(ok==0) dp1[i].add(j,1), dp2[j].add(i,1);
//   }
//   k = dp1[0].range(N-1,N-1);
//   wt(if[k,"B","A"]);
// }
0