結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー jp_ste
提出日時 2019-08-05 05:33:14
言語 JavaScript
(node v23.5.0)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 35 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 41,584 KB
最終ジャッジ日時 2024-10-13 01:13:45
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {
  const data = input.split("\n");
  const d = Number(data[0]);
  const c = data[1] + data[2];
  let realD = d;
  let realC = 'x'.repeat(d) + c + 'x'.repeat(d);
  let max = 0;
  for(let j=0; j<d; j++) {
    for(let i=0; i<realC.length-realD; i++) {
      if(haveLengthX(realC, i, realD)) {
        let len = countBeforA(realC, i-1) + realD + countAfterA(realC, i+realD);
        max = Math.max(max, len);
      }
    }
    realD--;
  }
  console.log(max);
}

function haveLengthX(list, start, length) {
  for(let i=start; i<start+length; i++) {
    if(list[i] == 'o') return false;
  }
  return true;
}

function countAfterA(list, start) {
  let count = 0;
  for(let i=start; i<list.length; i++) {
    if(list[i] == 'x') return count;
    count++;
  }
  return count;
}

function countBeforA(list, start) {
  let count = 0;
  for(let i=start; i>=0; i--) {
    if(list[i] == 'x') return count;
    count++;
  }
  return count;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0