結果

問題 No.2373 wa, wo, n
ユーザー nwonwo
提出日時 2023-06-16 18:59:23
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 1,950 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 133,620 KB
最終ジャッジ日時 2023-09-15 06:53:03
合計ジャッジ時間 10,886 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
43,048 KB
testcase_01 AC 84 ms
43,152 KB
testcase_02 AC 83 ms
43,000 KB
testcase_03 AC 84 ms
43,048 KB
testcase_04 AC 83 ms
43,068 KB
testcase_05 AC 83 ms
43,060 KB
testcase_06 AC 84 ms
43,056 KB
testcase_07 AC 83 ms
43,296 KB
testcase_08 AC 84 ms
43,052 KB
testcase_09 AC 83 ms
43,040 KB
testcase_10 AC 82 ms
42,956 KB
testcase_11 AC 84 ms
43,216 KB
testcase_12 AC 81 ms
43,056 KB
testcase_13 AC 83 ms
43,200 KB
testcase_14 AC 358 ms
115,564 KB
testcase_15 AC 175 ms
66,252 KB
testcase_16 AC 353 ms
116,368 KB
testcase_17 AC 188 ms
67,892 KB
testcase_18 AC 135 ms
52,656 KB
testcase_19 AC 221 ms
83,380 KB
testcase_20 AC 324 ms
115,896 KB
testcase_21 AC 222 ms
84,848 KB
testcase_22 AC 247 ms
86,956 KB
testcase_23 AC 379 ms
131,060 KB
testcase_24 AC 83 ms
43,104 KB
testcase_25 AC 85 ms
43,084 KB
testcase_26 AC 85 ms
43,112 KB
testcase_27 AC 83 ms
43,076 KB
testcase_28 AC 86 ms
43,300 KB
testcase_29 AC 84 ms
43,312 KB
testcase_30 AC 84 ms
43,304 KB
testcase_31 AC 86 ms
43,104 KB
testcase_32 AC 412 ms
132,740 KB
testcase_33 AC 385 ms
133,620 KB
testcase_34 AC 428 ms
130,952 KB
testcase_35 AC 358 ms
129,536 KB
testcase_36 AC 391 ms
130,556 KB
testcase_37 AC 384 ms
130,412 KB
testcase_38 AC 382 ms
130,004 KB
testcase_39 AC 384 ms
129,780 KB
testcase_40 AC 404 ms
132,872 KB
testcase_41 AC 400 ms
132,964 KB
testcase_42 AC 394 ms
130,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rl.on('line', (line) => {
  const N = parseInt(line);
  
  rl.on('line', (line) => {
    const S = line.trim();
    
    const dp = new Array(N).fill(false).map(() => new Array(26).fill(false));
    if (S[0] === '?') {
      for (let j = 0; j < 26; j++) {
        dp[0][j] = true;
      }
    }
    if (S[0] === 'n') {
      dp[0]['n'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
    }
    if (S[0] === 'w') {
      dp[0]['w'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
    }
    if (S[0] === 'a' || S[0] === 'o') {
      console.log("No");
      process.exit(0);
    }

    for (let i = 1; i < N; i++) {
      for (let j = 0; j < 26; j++) {
        if (dp[i - 1][j] === true) {
          if (j === 'w'.charCodeAt(0) - 'a'.charCodeAt(0)) {
            if (S[i] === 'a') dp[i]['a'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
            if (S[i] === 'o') dp[i]['o'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
            if (S[i] === '?') {
              dp[i]['a'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
              dp[i]['o'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
            }
          } else {
            if (S[i] === 'w') dp[i]['w'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
            if (S[i] === 'n') dp[i]['n'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
            if (S[i] === '?') {
              dp[i]['w'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
              dp[i]['n'.charCodeAt(0) - 'a'.charCodeAt(0)] = true;
            }
          }
        }
      }
    }

    let ans = false;
    if (dp[N - 1]['a'.charCodeAt(0) - 'a'.charCodeAt(0)]) ans = true;
    if (dp[N - 1]['o'.charCodeAt(0) - 'a'.charCodeAt(0)]) ans = true;
    if (dp[N - 1]['n'.charCodeAt(0) - 'a'.charCodeAt(0)]) ans = true;

    if (ans === true) console.log("Yes");
    else console.log("No");

    process.exit(0);
  });
});
0