結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー MNGOFMNGOF
提出日時 2020-04-27 01:09:11
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,742 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 265,132 KB
最終ジャッジ日時 2024-04-29 21:25:57
合計ジャッジ時間 15,861 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,712 KB
testcase_01 AC 43 ms
51,840 KB
testcase_02 AC 44 ms
52,608 KB
testcase_03 AC 120 ms
77,184 KB
testcase_04 AC 124 ms
77,440 KB
testcase_05 AC 128 ms
77,440 KB
testcase_06 AC 126 ms
77,696 KB
testcase_07 AC 126 ms
78,120 KB
testcase_08 AC 124 ms
77,440 KB
testcase_09 AC 124 ms
77,696 KB
testcase_10 AC 116 ms
76,544 KB
testcase_11 AC 348 ms
91,480 KB
testcase_12 AC 347 ms
92,176 KB
testcase_13 AC 383 ms
97,156 KB
testcase_14 AC 355 ms
92,504 KB
testcase_15 AC 373 ms
95,940 KB
testcase_16 AC 357 ms
93,072 KB
testcase_17 AC 362 ms
94,872 KB
testcase_18 AC 373 ms
93,268 KB
testcase_19 AC 379 ms
97,024 KB
testcase_20 AC 387 ms
95,240 KB
testcase_21 AC 375 ms
94,204 KB
testcase_22 AC 354 ms
91,924 KB
testcase_23 AC 357 ms
95,124 KB
testcase_24 AC 363 ms
92,920 KB
testcase_25 AC 377 ms
94,468 KB
testcase_26 AC 366 ms
93,612 KB
testcase_27 AC 369 ms
93,364 KB
testcase_28 AC 362 ms
93,288 KB
testcase_29 AC 379 ms
96,976 KB
testcase_30 AC 381 ms
96,312 KB
testcase_31 AC 386 ms
95,688 KB
testcase_32 AC 385 ms
95,228 KB
testcase_33 AC 390 ms
98,540 KB
testcase_34 AC 69 ms
77,568 KB
testcase_35 TLE -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(area):
    if len(area) <= 1:
        return 0
    selected_ind = [0] * len(area)
    max_ind = area.index(max(area))
    min_ind = max_ind
    for i in reversed(range(max_ind)):
        if area[min_ind] > area[i]:
            min_ind = i
            selected_ind[min_ind] = 1
    min_ind = max_ind
    for i in range(max_ind+1, len(area)):
        if area[min_ind] > area[i]:
            min_ind = i
            selected_ind[min_ind] = 1
    count = sum(selected_ind)

    tmp_sum = sum(selected_ind[0:max_ind])
    tmp_len = len(selected_ind[0:max_ind])
    if tmp_len == tmp_sum and tmp_len > 2:
        count += int(tmp_sum * (tmp_sum - 1) / 2)
    else:
        next_left_ind = max_ind
        if next_left_ind > 0:
            while area.index(max(area[0:next_left_ind])) == (next_left_ind - 1):
                tmp_sum -= 1
                count += tmp_sum
                next_left_ind -= 1
                if next_left_ind < 1:
                    break
        count += solve(area[0:next_left_ind])

    tmp_sum = sum(selected_ind[max_ind + 1: len(area)])
    tmp_len = len(selected_ind[max_ind + 1: len(area)])
    if tmp_len == tmp_sum and tmp_len > 2:
        count += int(tmp_sum * (tmp_sum - 1) / 2)
    else:
        next_right_ind = max_ind
        if next_right_ind < len(area) - 1:
            while area.index(max(area[next_right_ind + 1: len(area)])) == 0:
                tmp_sum -= 1
                count += tmp_sum
                next_right_ind += 1
                if next_right_ind > len(area) - 1:
                    break
        count += solve(area[next_right_ind + 1: len(area)])
    return int(count)
    

N = int(input())
data = input().split()
Input = [int(s) for s in data]

print(solve(Input))
0