結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー kenji_shioyakenji_shioya
提出日時 2017-01-08 01:16:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 580 ms / 2,000 ms
コード長 3,244 bytes
コンパイル時間 5,251 ms
コンパイル使用メモリ 78,500 KB
実行使用メモリ 64,316 KB
最終ジャッジ日時 2023-08-22 16:54:13
合計ジャッジ時間 16,740 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 188 ms
57,200 KB
testcase_01 AC 188 ms
57,488 KB
testcase_02 AC 187 ms
57,568 KB
testcase_03 AC 339 ms
62,196 KB
testcase_04 AC 340 ms
64,316 KB
testcase_05 AC 553 ms
62,148 KB
testcase_06 AC 532 ms
61,884 KB
testcase_07 AC 470 ms
61,592 KB
testcase_08 AC 465 ms
61,944 KB
testcase_09 AC 541 ms
61,824 KB
testcase_10 AC 341 ms
61,728 KB
testcase_11 AC 368 ms
61,928 KB
testcase_12 AC 394 ms
61,760 KB
testcase_13 AC 525 ms
61,724 KB
testcase_14 AC 550 ms
61,912 KB
testcase_15 AC 380 ms
62,036 KB
testcase_16 AC 328 ms
60,808 KB
testcase_17 AC 360 ms
62,124 KB
testcase_18 AC 294 ms
60,928 KB
testcase_19 AC 580 ms
61,708 KB
testcase_20 AC 562 ms
60,700 KB
testcase_21 AC 381 ms
62,228 KB
testcase_22 AC 375 ms
62,244 KB
testcase_23 AC 420 ms
63,144 KB
testcase_24 AC 527 ms
61,508 KB
testcase_25 AC 556 ms
61,604 KB
testcase_26 AC 470 ms
61,984 KB
testcase_27 AC 450 ms
61,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.BigDecimal;

public class Rain2 {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int quizCount = sc.nextInt();
    Map<String, Quiz> quizMap = new HashMap<String, Quiz>();
    for (int i = 0; i < quizCount; i++) {
      Quiz entry = new Quiz();
      entry.num = i;
      entry.getName();
      entry.stars = sc.nextInt();
      quizMap.put(entry.name, entry);
    }

    int submitNum = sc.nextInt();
    Map<String, Player> playerMap = new HashMap<String, Player>();
    List<Player> playerList = new ArrayList<Player>();
    for (int i = 0; i < submitNum; i++) {
      String playerName = sc.next();
      String quizName = sc.next();
      Player player = playerMap.get(playerName);
      Quiz quiz = quizMap.get(quizName);
      if (player != null) {
        player.scores[quiz.num] = calcPoint(quiz.stars, quiz.acCount);
        quiz.acCount += 1;
        player.getSum();
        getRank(playerList, player);
      } else {
        Player newPlayer = new Player(quizCount);
        newPlayer.name = playerName;
        newPlayer.scores[quiz.num] = calcPoint(quiz.stars, quiz.acCount);
        quiz.acCount += 1;
        playerList.add(newPlayer);
        newPlayer.getSum();
        playerMap.put(playerName, newPlayer);
        getRank(playerList, newPlayer);
      }
    }
    showResult(playerList);

  }

  private static void showResult(List<Player> playerList) {

    for (int i = 0; i < playerList.size(); i++) {
      Player player = playerList.get(i);
      String point = "";
      for (int j = 0; j < player.scores.length; j++) {
        point += player.scores[j] + " ";
      }
      System.out.println((i + 1) + " " + player.name + " " + point + player.sum);
    }
  }

  private static void getRank(List<Player> playerList, Player player) {
    if (playerList.size() > 1){
      playerList.remove(player);
      int size = playerList.size();

      for (int i = 0; i < size; i++) {
        if (player.sum > playerList.get(i).sum) {
          playerList.add(i, player);
          return;
        }
        if (i == playerList.size()-1) {
          playerList.add(i + 1, player);
        }
      }
    }
  }

  private static int calcPoint(int stars, int acCount){
    BigDecimal a = new BigDecimal(stars);
    BigDecimal b = new BigDecimal(acCount);
    BigDecimal c = new BigDecimal("0.8");
    BigDecimal d = new BigDecimal("0.2");
    BigDecimal e = new BigDecimal(50*stars);
    return (stars * 50 + e.divide(c.add(d.multiply(b)), 0, BigDecimal.ROUND_FLOOR).intValue());
  }
}

class Quiz {
  public String name;
  public int stars;
  public int num;
  public int acCount = 1;

  public void getName() {
    String[] nameArray = {"A","B","C","D","E","F","G","H","I","J","K","L",
    "M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
    this.name = nameArray[this.num];
  }
}

class Player {
   public String name;
   public int[] scores;
   public int sum;

   public Player(int quizCount) {
     scores = new int[quizCount];
     for (int i = 0; i < quizCount; i++) {
       scores[i] = 0;
     }
   }

   public void getSum() {
     int sum = 0;
     for (int num : scores) {
       sum += num;
     }
     this.sum = sum;
   }
 }
0