結果
| 問題 |
No.205 マージして辞書順最小
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-28 17:15:27 |
| 言語 | JavaScript (node v23.5.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,064 bytes |
| コンパイル時間 | 38 ms |
| コンパイル使用メモリ | 6,816 KB |
| 実行使用メモリ | 54,192 KB |
| 最終ジャッジ日時 | 2024-10-13 00:42:43 |
| 合計ジャッジ時間 | 4,492 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 5 WA * 5 RE * 5 |
ソースコード
function Main(input) {
var data = input.split("\n").filter(s => s.length > 0)
var n = data.shift() * 1
let r = ''
function findMinIdx(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 nextInputIndex = []
let nextInput = input.filter((s, i) => {
let isNext = s.charCodeAt(0) == minCode
if (isNext){
nextInputIndex.push(i)
}
return isNext
}).map(s => s.slice(1))
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"));