結果

問題 No.973 余興
ユーザー LayCurseLayCurse
提出日時 2020-01-17 22:05:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,300 bytes
コンパイル時間 2,440 ms
コンパイル使用メモリ 210,964 KB
実行使用メモリ 199,276 KB
最終ジャッジ日時 2023-09-08 03:13:02
合計ジャッジ時間 54,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,697 ms
198,948 KB
testcase_01 WA -
testcase_02 AC 1,643 ms
198,948 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1,646 ms
198,944 KB
testcase_06 AC 1,612 ms
199,024 KB
testcase_07 AC 1,624 ms
198,816 KB
testcase_08 AC 1,720 ms
198,120 KB
testcase_09 AC 1,624 ms
199,040 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 427 ms
73,196 KB
testcase_14 WA -
testcase_15 AC 39 ms
11,256 KB
testcase_16 AC 40 ms
11,556 KB
testcase_17 WA -
testcase_18 AC 31 ms
9,712 KB
testcase_19 AC 31 ms
9,732 KB
testcase_20 AC 23 ms
8,224 KB
testcase_21 AC 39 ms
11,220 KB
testcase_22 WA -
testcase_23 AC 31 ms
9,848 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 31 ms
9,936 KB
testcase_29 WA -
testcase_30 AC 1,387 ms
199,108 KB
testcase_31 AC 1,424 ms
199,052 KB
testcase_32 AC 1,446 ms
199,192 KB
testcase_33 AC 1,384 ms
198,808 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 1,387 ms
193,816 KB
testcase_37 AC 1,365 ms
194,008 KB
testcase_38 WA -
testcase_39 AC 1,428 ms
198,760 KB
testcase_40 AC 1 ms
4,384 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 AC 2 ms
4,376 KB
testcase_46 WA -
testcase_47 AC 1,375 ms
198,900 KB
testcase_48 WA -
testcase_49 AC 1,265 ms
181,892 KB
testcase_50 WA -
testcase_51 AC 1,379 ms
199,260 KB
testcase_52 AC 1,390 ms
199,132 KB
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
権限があれば一括ダウンロードができます

ソースコード

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]), j-1)){
        ok++;
      }
      if(len > 1 && dp2[j].range(i+1,min_L(j, rg[i]))){
        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 20200112-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]), j-1)) ok++;
//     if(len > 1 && dp2[j].range(i+1,min(j,rg[i]))) 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