結果
| 問題 |
No.1628 Sorting Integers (MAX of M)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-31 03:57:12 |
| 言語 | TypeScript (5.7.2) |
| 結果 |
AC
|
| 実行時間 | 77 ms / 2,000 ms |
| コード長 | 819 bytes |
| コンパイル時間 | 8,515 ms |
| コンパイル使用メモリ | 228,732 KB |
| 実行使用メモリ | 42,300 KB |
| 最終ジャッジ日時 | 2024-12-31 16:40:29 |
| 合計ジャッジ時間 | 9,860 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 |
ソースコード
let lines: string[] = [];
const reader = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
reader.on('line', function (line: string) {
lines.push(line);
if (lines.length === 2) {
reader.close();
main();
}
});
function main () {
const n = +lines[0];
const nums = lines[1].split(' ').map((s,i) => [i+1, +s]).filter(e => e[1]);
const res = result(n, nums);
console.log(res);
}
function result (n: number, nums: number[][], res = 0): number {
if (n === 0) return res;
else {
if (nums[nums.length-1][1] === 1) return result(n-1, nums.slice(0,nums.length-1), res * 10 + nums[nums.length-1][0]);
else return result(n-1, [...nums.slice(0,nums.length-1), [nums[nums.length-1][0], nums[nums.length-1][1]-1]], res * 10 + nums[nums.length-1][0]);
}
}