結果

問題 No.112 ややこしい鶴亀算
ユーザー ontama_12ontama_12
提出日時 2016-09-29 15:04:02
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 1,128 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 39,296 KB
最終ジャッジ日時 2024-04-21 01:33:36
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
39,040 KB
testcase_01 AC 65 ms
38,912 KB
testcase_02 AC 61 ms
38,912 KB
testcase_03 AC 60 ms
39,168 KB
testcase_04 AC 62 ms
39,040 KB
testcase_05 AC 61 ms
39,296 KB
testcase_06 AC 61 ms
39,168 KB
testcase_07 AC 61 ms
39,168 KB
testcase_08 AC 63 ms
38,912 KB
testcase_09 AC 62 ms
39,168 KB
testcase_10 AC 64 ms
39,040 KB
testcase_11 AC 63 ms
39,040 KB
testcase_12 AC 63 ms
39,168 KB
testcase_13 AC 62 ms
39,296 KB
testcase_14 AC 65 ms
39,040 KB
testcase_15 AC 62 ms
38,912 KB
testcase_16 AC 61 ms
38,912 KB
testcase_17 AC 62 ms
38,912 KB
testcase_18 AC 63 ms
39,040 KB
testcase_19 AC 63 ms
39,040 KB
testcase_20 AC 61 ms
39,040 KB
testcase_21 AC 64 ms
39,040 KB
testcase_22 AC 64 ms
39,296 KB
testcase_23 AC 63 ms
39,040 KB
testcase_24 AC 61 ms
39,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

    /////////////////////////////////No.112 ややこしい鶴亀算
    //入力文字読み取り
    var inputall = require('fs').readFileSync('/dev/stdin', 'utf8');

    //すべて受け取り改行で区切って格納
    var input = inputall.split("\n");

    //動物数
    var animals = Number(input[0]);

    //動物が数えた足の総本数
    var animal_legs = input[1].split(" ").map(Number);
    
    var max = -1;
    var min = 10000000000;

    var sum = 0;

    for (var i = 0; i < animals; i++) {
        max = Math.max(max, animal_legs[i]);
        min = Math.min(min, animal_legs[i]);
        sum += animal_legs[i];
    }

    var crane_count = 0;
    var turtle_count = 0;

    for (var i = 0; i < animals; i++) {
        if (max == min) {
            if (( animals-1)*2 ==max) {
                crane_count++;
            } else {
                turtle_count++;
            }
        } else {
            if (animal_legs[i] == max) {
                crane_count++;
            } else {
                turtle_count++;
            }
        }
    }

    console.log(crane_count + " " + turtle_count);
0