結果

問題 No.761 平均値ゲーム
ユーザー LyricalMaestro
提出日時 2024-05-08 02:46:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 93,136 KB
最終ジャッジ日時 2024-12-14 02:36:22
合計ジャッジ時間 14,366 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 100
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/761

import sys

sys.setrecursionlimit(100100)

def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    a_cum_list = [0] * (N + 1)
    for i in range(N):
        a_cum_list[i + 1] = a_cum_list[i] + A[i]
    

    def dfs(i, j, index):
        # 平均値計算
        a = a_cum_list[j + 1] - a_cum_list[i]
        n = j - i + 1

        # 分割点の計算
        if a <= n * A[i]:
            return 1 # index(first or second)の勝ち!
        else:
            low = i
            high = j
            while high - low > 1:
                mid = (low + high) // 2
                if A[mid] * n >= a:
                    high = mid
                else:
                    low = mid
            if A[low] * n >= a:
                a1 = dfs(i, low  - 1, 1 - index)
                a2 = dfs(low, j, 1 - index)
                if a1 == 0 or a2 == 0:
                    return 1
                else:
                    return 0 
            else:
                a1 = dfs(i, high  - 1, 1 - index)
                a2 = dfs(high, j, 1 - index)
                if a1 == 0 or a2 == 0:
                    return 1
                else:
                    return 0 


    result = dfs(0, N - 1, 0)
    if result == 0:
        print("Second")
    else:
        print("First")










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