結果
| 問題 |
No.956 Number of Unbalanced
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:41:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 618 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 81,932 KB |
| 実行使用メモリ | 55,088 KB |
| 最終ジャッジ日時 | 2025-06-12 21:45:15 |
| 合計ジャッジ時間 | 4,399 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()
gew1fw