結果

問題 No.935 う し た ぷ に き あ く ん 笑 ビ - ム
ユーザー jp_stejp_ste
提出日時 2020-05-04 10:26:32
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 872 ms / 2,000 ms
コード長 2,909 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 46,592 KB
最終ジャッジ日時 2024-04-21 03:27:40
合計ジャッジ時間 24,748 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 177 ms
45,568 KB
testcase_01 AC 340 ms
45,824 KB
testcase_02 AC 105 ms
45,824 KB
testcase_03 AC 357 ms
45,696 KB
testcase_04 AC 386 ms
45,824 KB
testcase_05 AC 117 ms
45,824 KB
testcase_06 AC 589 ms
46,080 KB
testcase_07 AC 557 ms
46,080 KB
testcase_08 AC 872 ms
46,336 KB
testcase_09 AC 661 ms
45,696 KB
testcase_10 AC 727 ms
45,952 KB
testcase_11 AC 818 ms
46,336 KB
testcase_12 AC 66 ms
39,168 KB
testcase_13 AC 65 ms
39,040 KB
testcase_14 AC 66 ms
39,296 KB
testcase_15 AC 66 ms
39,424 KB
testcase_16 AC 65 ms
39,424 KB
testcase_17 AC 125 ms
45,568 KB
testcase_18 AC 311 ms
45,952 KB
testcase_19 AC 655 ms
45,952 KB
testcase_20 AC 524 ms
45,696 KB
testcase_21 AC 166 ms
45,568 KB
testcase_22 AC 103 ms
45,824 KB
testcase_23 AC 79 ms
43,648 KB
testcase_24 AC 85 ms
43,136 KB
testcase_25 AC 82 ms
43,136 KB
testcase_26 AC 73 ms
43,136 KB
testcase_27 AC 71 ms
43,136 KB
testcase_28 AC 82 ms
43,264 KB
testcase_29 AC 94 ms
43,648 KB
testcase_30 AC 82 ms
43,136 KB
testcase_31 AC 79 ms
43,648 KB
testcase_32 AC 91 ms
43,776 KB
testcase_33 AC 551 ms
45,824 KB
testcase_34 AC 758 ms
46,208 KB
testcase_35 AC 705 ms
46,336 KB
testcase_36 AC 260 ms
45,952 KB
testcase_37 AC 553 ms
45,824 KB
testcase_38 AC 576 ms
45,952 KB
testcase_39 AC 784 ms
46,208 KB
testcase_40 AC 822 ms
46,208 KB
testcase_41 AC 817 ms
46,208 KB
testcase_42 AC 688 ms
45,824 KB
testcase_43 AC 833 ms
46,080 KB
testcase_44 AC 467 ms
45,696 KB
testcase_45 AC 821 ms
46,592 KB
testcase_46 AC 216 ms
45,696 KB
testcase_47 AC 517 ms
46,080 KB
testcase_48 AC 376 ms
45,696 KB
testcase_49 AC 452 ms
46,080 KB
testcase_50 AC 515 ms
45,696 KB
testcase_51 AC 593 ms
45,952 KB
testcase_52 AC 584 ms
45,824 KB
testcase_53 AC 755 ms
46,080 KB
testcase_54 AC 262 ms
45,824 KB
testcase_55 AC 126 ms
45,568 KB
testcase_56 AC 664 ms
45,824 KB
testcase_57 AC 537 ms
46,080 KB
testcase_58 AC 68 ms
39,168 KB
testcase_59 AC 67 ms
39,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(input) {
  let [N] = getIntegers(input);
  let S = input.shift().split("");
  let A = getIntegers(input);
  let [Q] = getIntegers(input);
  let K = getIntegers(input);
  
  let dp = [A[0]];
  for(let i=1; i<N; i++) {
    dp[i] = dp[i-1] + A[i];
  }
  let dp2 = [S[0]=='E'?1:0];
  for(let i=1; i<N; i++) {
    dp2[i] = dp2[i-1] + (S[i]=='E'?1:0);
  }
  
  for(let i=0; i<Q; i++) {
    let max = 0;
    for(let j=0; j<N; j++) {
      let v = j>0 ? dp[j-1] : 0;
      let index = binary(S,K[i],dp, j, v);
      let num = 0;
      if(index > 0) {
        num = dp2[j+index-1] - dp2[j] + (S[j]=='E'?1:0);
      }
      max = Math.max(max, num);
      if(max == N) break;
    }
    console.log(max);
  }
}

function binary(S,K,DP,j,v) {
  let l = 0;
  let r = S.length;
  let count = 11;
  while(count-- > 0) {
    let X = Math.floor((l + r) / 2);
    if(K >= DP[X+j]-v) {
      l = X;
    } else {
      r = X;
    }
  }
  return r;
}

//-- functions ------------------------------------

function getIntegers(lines) {
  return lines.shift().split(" ").map(function(e) {
    return Number(e);
  });
}

function getBigIntegers(lines) {
  return lines.shift().split(" ").map(function(e) {
    return BigInt(e);
  });
}

function getStrings(lines) {
  return lines.shift().split(" ");
}

function twoDimenArrayByValue(h, w, value) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = new Array(w).fill().map(function(e) {
      return value.constructor == Array ? Array.from(value) : value;
    });
  }
  return list;
}

function twoDimenArrayByStrings(h, strings) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = strings.shift().split("");
  }
  return list;
}

function distance(x1, y1, x2, y2) {
  return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
}

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}

//-- Array -------------------------------------------

Array.prototype.deepCopy = function(list) {
  let retList = [];
  for(let i=0; i<list.length; i++) {
    retList[i] = list[i].constructor == Array ? Array.from(list[i]) : list[i];
  }
  return retList;
};

Array.prototype.out = function() {
  let outList = [];
  if(this[0].constructor == Array) {
    for(let i=0; i<this.length; i++) {
      outList.push(this[i].oneLineString());
    } 
  } else {
    outList.push(this.oneLineString());
  }
  console.log(outList.join("\n") + "\n");
};

Array.prototype.pushNoSameValue = function(...values) {
  values.forEach(function(e) {
    if(!this.includes(e)) {
      this.push(e);
    }
  }, this);
};

Array.prototype.sortByIntegers = function() {
  this.sort(function(a, b) {
    return a - b;
  });
};

Array.prototype.oneLineString = function() {
  let str = "";
  this.forEach(function(e, i) {
    if(i > 0) str += " ";
    str += e;
  });
  return str;
};

main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));
0