結果

問題 No.709 優勝可能性
ユーザー lam6er
提出日時 2025-03-31 17:50:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 348 ms / 3,500 ms
コード長 1,687 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 203,068 KB
最終ジャッジ日時 2025-03-31 17:50:55
合計ジャッジ時間 5,833 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    N = int(data[idx])
    M = int(data[idx + 1])
    idx += 2
    
    R = []
    for _ in range(N):
        R.append(list(map(int, data[idx:idx + M])))
        idx += M
    
    current_max_val = [0] * M
    current_max_people = [set() for _ in range(M)]
    active = [0] * (N + 2)  # 1-based indexing
    result = 0
    answers = []
    
    for k in range(1, N + 1):
        row = R[k-1]
        for j in range(M):
            val = row[j]
            if val > current_max_val[j]:
                # Process previous max people
                prev_people = current_max_people[j]
                for i in prev_people:
                    old = active[i]
                    active[i] -= 1
                    new = active[i]
                    if old == 1 and new == 0:
                        result -= 1
                current_max_people[j].clear()
                current_max_val[j] = val
                current_max_people[j].add(k)
                # Now add k
                old = active[k]
                active[k] += 1
                new = active[k]
                if old == 0 and new == 1:
                    result += 1
            elif val == current_max_val[j]:
                if k not in current_max_people[j]:
                    current_max_people[j].add(k)
                    old = active[k]
                    active[k] += 1
                    new = active[k]
                    if old == 0 and new == 1:
                        result += 1
        answers.append(result)
    
    for ans in answers:
        print(ans)

if __name__ == '__main__':
    main()
0