結果

問題 No.205 マージして辞書順最小
ユーザー dsxsdsxs
提出日時 2018-09-28 17:35:55
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 1,384 ms / 5,000 ms
コード長 1,391 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 54,864 KB
最終ジャッジ日時 2024-04-21 02:13:19
合計ジャッジ時間 6,285 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
39,296 KB
testcase_01 AC 67 ms
39,296 KB
testcase_02 AC 101 ms
45,440 KB
testcase_03 AC 134 ms
45,312 KB
testcase_04 AC 106 ms
45,696 KB
testcase_05 AC 112 ms
45,568 KB
testcase_06 AC 64 ms
39,424 KB
testcase_07 AC 227 ms
47,284 KB
testcase_08 AC 131 ms
45,440 KB
testcase_09 AC 225 ms
46,968 KB
testcase_10 AC 1,384 ms
52,612 KB
testcase_11 AC 1,026 ms
54,864 KB
testcase_12 AC 815 ms
53,996 KB
testcase_13 AC 469 ms
49,600 KB
testcase_14 AC 70 ms
40,320 KB
testcase_15 AC 66 ms
39,424 KB
testcase_16 AC 67 ms
39,296 KB
testcase_17 AC 64 ms
39,296 KB
testcase_18 AC 67 ms
39,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input) {

    var data = input.split("\n").filter(s => s.length > 0)
    var n = data.shift() * 1
let r = ''

    function findMinIdx(input){
    // console.log(input)
    const codes = input.map(s=>s.slice(0, 1)).map(s=>[].reduce.call(s, (sum ,c)=> sum += c.charCodeAt(0), 0))
    const minCode = Math.min(...codes)
    const minIdxes = codes.map((c, i) => [c, i]).filter(a => a[0] == minCode).map(a => a[1])
    if (minIdxes.length == 1) {
        return minIdxes.pop()
    }
    let next = input.filter((s, i) => s.charCodeAt(0) == minCode && s.length == 1)
    let nextInputIndex = []
    if (nextInputIndex.length > 0){
        return nextInputIndex.pop()
    }
    let nextInput = input.filter((s, i) => {
        let isNext = s.charCodeAt(0) == minCode
        if (isNext && s.length > 1){
            nextInputIndex.push(i)
        }
        return isNext
    }).map(s => s.slice(1)).filter(s => s.length > 0)
    if (nextInput.length < 1) {
        return minIdxes.pop()
    }
    // console.log(nextInput)
    return nextInputIndex[findMinIdx(nextInput)]
}
var input = data
while (input.length > 0) {
    
    const minIdx = findMinIdx(input) 
    const str = input[minIdx]
    r += str[0]
    input[minIdx] = str.slice(1)
    input = input.filter(s => s.length > 0)
}
console.log(r)
}

// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0