結果

問題 No.709 優勝可能性
ユーザー tenten
提出日時 2022-08-12 08:44:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 585 ms / 3,500 ms
コード長 2,181 bytes
コンパイル時間 4,606 ms
コンパイル使用メモリ 78,948 KB
実行使用メモリ 80,244 KB
最終ジャッジ日時 2024-09-22 12:57:39
合計ジャッジ時間 9,793 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

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 m = sc.nextInt();
        ArrayList<ArrayList<Integer>> probables = new ArrayList<>();
        for (int i = 0; i < m; i++) {
            probables.add(new ArrayList<>());
        }
        int[] maxes = new int[m];
        StringBuilder sb = new StringBuilder();
        int[] prizes = new int[n];
        int count = 0;
        for (int j = 0; j < n; j++) {
            for (int i = 0; i < m; i++) {
                int x = sc.nextInt();
                if (maxes[i] < x) {
                    for (int y : probables.get(i)) {
                        prizes[y]--;
                        if (prizes[y] == 0) {
                            count--;
                        }
                    }
                    probables.get(i).clear();
                    probables.get(i).add(j);
                    maxes[i] = x;
                    if (prizes[j] == 0) {
                        count++;
                    }
                    prizes[j]++;
                } else if (maxes[i] == x) {
                    probables.get(i).add(j);
                    if (prizes[j] == 0) {
                        count++;
                    }
                    prizes[j]++;
                }
            }
            sb.append(count).append("\n");
        }
        System.out.print(sb);
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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