結果

問題 No.504 ゲーム大会(ランキング)
ユーザー nihi9119nihi9119
提出日時 2017-05-29 17:50:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 705 ms / 2,000 ms
コード長 2,958 bytes
コンパイル時間 3,430 ms
コンパイル使用メモリ 78,220 KB
実行使用メモリ 69,416 KB
最終ジャッジ日時 2023-10-21 16:56:08
合計ジャッジ時間 10,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,536 KB
testcase_01 AC 55 ms
53,540 KB
testcase_02 AC 56 ms
52,484 KB
testcase_03 AC 55 ms
53,540 KB
testcase_04 AC 55 ms
53,536 KB
testcase_05 AC 56 ms
53,548 KB
testcase_06 AC 54 ms
53,536 KB
testcase_07 AC 699 ms
69,364 KB
testcase_08 AC 705 ms
68,724 KB
testcase_09 AC 692 ms
69,364 KB
testcase_10 AC 699 ms
68,544 KB
testcase_11 AC 689 ms
69,416 KB
testcase_12 AC 680 ms
68,736 KB
testcase_13 AC 677 ms
66,736 KB
testcase_14 AC 682 ms
69,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test_5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * No.504 ゲーム大会(ランキング)
 *
 * K 君はゲーム大会にやってきた。 このゲームは、できるだけ高いスコアを目指すゲームである。 K君を含めてNN人が参加している。
 * 順番に1回ずつプレイしていき、随時ランキングが更新されていく。 K君は最初にプレイする。
 * それぞれの人がプレイし終わった時に、K君が何位にいるかを求めよ。 スコアが高い方の順位が上になる。 同点の場合は先にプレイした方の順位が上とする。
 */

public class Question_06_0526_1 {

	static final int NUM_MIN = 1;
	static final int NUM_MAX = (int) Math.pow(10, 5);
	static final int SCORE_MIN = 1;
	static final int SCORE_MAX = (int) Math.pow(10, 9);

	static int[] kRankList; // k君の順位
	static int kScore; // k君のスコア

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			// N(人数)取得
			String stringPeople = br.readLine();
			int numPeople = Integer.parseInt(stringPeople);

			// 人数が有効範囲か確認
			if (NumJudg(numPeople, NUM_MAX, NUM_MIN)) {
				// 人数で初期化
				kRankList = new int[numPeople];
				// 人数分処理する
				for (int i = 0; i < numPeople; i++) {
					int score = Integer.parseInt(br.readLine());
					if (i == 0) {
						kScore = score;
						kRankList[i] = 1; // 最初はK君が1位
					} else {
						kRankList[i] = RankJudg(score, i);
					}
				}
				// 順位表示
				for (int ranking : kRankList) {
					System.out.println(ranking);
				}
			} else {
				System.out.println("数値が有効範囲外です。");
			}
		} catch (NumberFormatException e) {
			System.out.println("数字を入力して下さい。");
		} catch (IOException e) {
			System.out.println("エラーが発生しました。");
		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}

		}
	}

	/**
	 * 有効値判定
	 * @param num 判定する数字
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean NumJudg(int num, int max, int min) {
		Boolean result = false;
		if (min <= num && num <= max) {
			result = true;
		}
		return result;
	}

	/**
	 * 順位判定
	 * @param score 点数
	 * @param count 何人目か
	 * @return 現在の順位
	 */
	static private int RankJudg(int score, int count) {
		//抜かされたらランキングを更新
		if (score > kScore) {
			kRankList[count] = kRankList[count - 1] + 1;
		} else {
			kRankList[count] = kRankList[count - 1];
		}
		return kRankList[count];
	}

}
0