結果
| 問題 | No.956 Number of Unbalanced | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 21:40:12 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 618 bytes | 
| コンパイル時間 | 566 ms | 
| コンパイル使用メモリ | 81,992 KB | 
| 実行使用メモリ | 54,828 KB | 
| 最終ジャッジ日時 | 2025-06-12 21:44:08 | 
| 合計ジャッジ時間 | 4,800 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | TLE * 1 -- * 23 | 
ソースコード
import sys
from collections import defaultdict
def count_unbalanced_subarrays(A):
    n = len(A)
    count = 0
    for i in range(n):
        freq = defaultdict(int)
        max_freq = 0
        for j in range(i, n):
            num = A[j]
            freq[num] += 1
            if freq[num] > max_freq:
                max_freq = freq[num]
            if max_freq > (j - i + 1) // 2:
                count += 1
    return count
def main():
    input = sys.stdin.read().split()
    n = int(input[0])
    A = list(map(int, input[1:n+1]))
    print(count_unbalanced_subarrays(A))
if __name__ == "__main__":
    main()
            
            
            
        