結果
| 問題 | No.935 う し た ぷ に き あ く ん 笑 ビ - ム | 
| コンテスト | |
| ユーザー |  jp_ste | 
| 提出日時 | 2020-05-04 10:26:32 | 
| 言語 | JavaScript (node v23.5.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 842 ms / 2,000 ms | 
| コード長 | 2,909 bytes | 
| コンパイル時間 | 30 ms | 
| コンパイル使用メモリ | 5,120 KB | 
| 実行使用メモリ | 46,336 KB | 
| 最終ジャッジ日時 | 2024-10-13 01:48:01 | 
| 合計ジャッジ時間 | 23,372 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 58 | 
ソースコード
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"));
            
            
            
        