結果

問題 No.112 ややこしい鶴亀算
ユーザー samplelpmassamplelpmas
提出日時 2017-01-22 21:06:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 5,000 ms
コード長 778 bytes
コンパイル時間 2,659 ms
コンパイル使用メモリ 73,160 KB
実行使用メモリ 58,788 KB
最終ジャッジ日時 2023-08-24 20:05:53
合計ジャッジ時間 9,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
54,904 KB
testcase_01 AC 149 ms
57,136 KB
testcase_02 AC 148 ms
56,880 KB
testcase_03 AC 149 ms
56,844 KB
testcase_04 AC 150 ms
56,500 KB
testcase_05 AC 149 ms
56,548 KB
testcase_06 AC 148 ms
56,708 KB
testcase_07 AC 150 ms
56,848 KB
testcase_08 AC 153 ms
56,920 KB
testcase_09 AC 149 ms
56,768 KB
testcase_10 AC 149 ms
58,788 KB
testcase_11 AC 151 ms
55,064 KB
testcase_12 AC 147 ms
56,764 KB
testcase_13 AC 150 ms
56,948 KB
testcase_14 AC 154 ms
56,804 KB
testcase_15 AC 155 ms
56,732 KB
testcase_16 AC 156 ms
58,700 KB
testcase_17 AC 154 ms
54,572 KB
testcase_18 AC 154 ms
56,732 KB
testcase_19 AC 153 ms
56,712 KB
testcase_20 AC 154 ms
57,088 KB
testcase_21 AC 155 ms
56,900 KB
testcase_22 AC 158 ms
56,736 KB
testcase_23 AC 154 ms
56,716 KB
testcase_24 AC 156 ms
56,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int numAnimals = sc.nextInt();
        int legs[] = new int[numAnimals];

        int legsSum = 0;

        for (int i = 0; i < numAnimals; i++) {
            legs[i] = sc.nextInt();
            legsSum += legs[i];
        }

        legsSum /= numAnimals - 1;

        int cranesCount = 0;
        int turtlesCount = 0;

        for (int i = 0; i < numAnimals; i++) {

            if (legsSum - legs[i] == 2) {
                cranesCount++;
            }

            if (legsSum - legs[i] == 4) {
                turtlesCount++;
            }

        }

        System.out.println(cranesCount + " " + turtlesCount);

    }

}
0