結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー tentententen
提出日時 2022-10-14 13:04:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 2,893 bytes
コンパイル時間 2,534 ms
コンパイル使用メモリ 76,504 KB
実行使用メモリ 55,748 KB
最終ジャッジ日時 2023-09-08 19:40:24
合計ジャッジ時間 7,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,324 KB
testcase_01 AC 46 ms
49,852 KB
testcase_02 AC 45 ms
49,436 KB
testcase_03 AC 118 ms
53,160 KB
testcase_04 AC 114 ms
53,212 KB
testcase_05 AC 133 ms
54,948 KB
testcase_06 AC 142 ms
55,316 KB
testcase_07 AC 137 ms
53,200 KB
testcase_08 AC 139 ms
53,328 KB
testcase_09 AC 151 ms
54,928 KB
testcase_10 AC 92 ms
52,360 KB
testcase_11 AC 120 ms
53,064 KB
testcase_12 AC 132 ms
53,072 KB
testcase_13 AC 147 ms
55,284 KB
testcase_14 AC 146 ms
55,108 KB
testcase_15 AC 123 ms
53,120 KB
testcase_16 AC 106 ms
52,536 KB
testcase_17 AC 119 ms
52,980 KB
testcase_18 AC 84 ms
51,784 KB
testcase_19 AC 159 ms
55,748 KB
testcase_20 AC 154 ms
54,972 KB
testcase_21 AC 123 ms
53,200 KB
testcase_22 AC 119 ms
52,996 KB
testcase_23 AC 129 ms
53,232 KB
testcase_24 AC 148 ms
55,240 KB
testcase_25 AC 153 ms
55,244 KB
testcase_26 AC 133 ms
53,068 KB
testcase_27 AC 128 ms
53,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] levels = new int[n];
        for (int i = 0; i < n; i++) {
            levels[i] = sc.nextInt();
        }
        int[] ranks = new int[n];
        int t = sc.nextInt();
        HashMap<String, Player> players = new HashMap<>();
        Player.size = n;
        for (int i = 0; i < t; i++) {
            String name = sc.next();
            int idx = sc.next().charAt(0) - 'A';
            ranks[idx]++;
            if (!players.containsKey(name)) {
                players.put(name, new Player(name));
            }
            players.get(name).addScore(idx, 50 * levels[idx] + 500 * levels[idx] / (8 + 2 * ranks[idx]), i);
        }
        ArrayList<Player> ans = new ArrayList<>();
        ans.addAll(players.values());
        Collections.sort(ans);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ans.size(); i++) {
            sb.append(i + 1).append(" ").append(ans.get(i)).append("\n");
        }
        System.out.print(sb);
    }
    
    static class Player implements Comparable<Player> {
        static int size;
        String name;
        int[] scores;
        int sum;
        int last;
        
        public Player(String name) {
            this.name = name;
            scores = new int[size];
        }
        
        public void addScore(int idx, int value, int time) {
            scores[idx] = value;
            sum += value;
            last = time;
        }
        
        public int compareTo(Player another) {
            if (sum == another.sum) {
                return last - another.last;
            } else {
                return another.sum - sum;
            }
        }
        
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(name).append(" ");
            for (int x : scores) {
                sb.append(x).append(" ");
            }
            sb.append(sum);
            return sb.toString();
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0