結果

問題 No.349 干支の置き物
ユーザー matsuyoshi30matsuyoshi30
提出日時 2017-01-25 00:08:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 1,183 bytes
コンパイル時間 2,039 ms
コンパイル使用メモリ 74,532 KB
実行使用メモリ 56,436 KB
最終ジャッジ日時 2023-08-24 21:57:38
合計ジャッジ時間 7,439 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
53,708 KB
testcase_01 AC 124 ms
55,968 KB
testcase_02 AC 123 ms
56,096 KB
testcase_03 AC 124 ms
55,752 KB
testcase_04 AC 129 ms
56,040 KB
testcase_05 AC 126 ms
55,756 KB
testcase_06 AC 128 ms
56,028 KB
testcase_07 AC 126 ms
56,016 KB
testcase_08 AC 128 ms
56,000 KB
testcase_09 AC 127 ms
55,720 KB
testcase_10 AC 124 ms
56,088 KB
testcase_11 AC 126 ms
56,172 KB
testcase_12 AC 128 ms
55,832 KB
testcase_13 AC 127 ms
56,160 KB
testcase_14 AC 126 ms
56,240 KB
testcase_15 AC 125 ms
56,076 KB
testcase_16 AC 125 ms
55,768 KB
testcase_17 AC 123 ms
55,756 KB
testcase_18 AC 124 ms
55,912 KB
testcase_19 AC 123 ms
56,176 KB
testcase_20 AC 123 ms
55,816 KB
testcase_21 AC 123 ms
55,564 KB
testcase_22 AC 125 ms
56,012 KB
testcase_23 AC 124 ms
56,244 KB
testcase_24 AC 125 ms
56,020 KB
testcase_25 AC 122 ms
56,120 KB
testcase_26 AC 126 ms
55,464 KB
testcase_27 AC 130 ms
56,436 KB
testcase_28 AC 131 ms
55,716 KB
testcase_29 AC 129 ms
56,128 KB
testcase_30 AC 132 ms
55,880 KB
testcase_31 AC 128 ms
55,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String[] a = new String[n];

        for(int i=0; i<n; i++) {
            a[i] = in.next();
        }

        /*
          N個の干支の置物がある
          12種類の干支のうち、どれかひとつでもN/2+1個以上あれば
          隣に置かざるをえない
         */

        String[] eto = {"ne", "ushi", "tora", "u", "tatsu", "mi", "uma", "hitsuji", "saru", "tori", "inu", "i"};

        String ans = "";

        if(n == 2 && a[0].equals(a[1])) {
            ans = "NO";
        } else {
            ans = "YES";
        }

        for(int i=0; i<12; i++) {
            int count = 0;
            for(int j=0; j<n; j++) {
                if(a[j].equals(eto[i])) {
                    count++;
                }
            }
            if(count > (n+1) / 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);

        in.close();
    }
}
0