提出 #66808142


ソースコード 拡げる

from heapq import *


def solve():
    n = int(input())
    L = [0] * n
    R = [0] * n
    for i in range(n):
        L[i], R[i] = map(int, input().split())

    to = [[False] * n for _ in range(n)]
    for i in range(n):
        li, ri = L[i], R[i]
        for j in range(i + 1, n):
            lj, rj = L[j], R[j]
            if li < lj < rj < ri:
                to[i][j] = True
            elif lj < li < ri < rj:
                to[j][i] = True

    for k in range(n):
        for i in range(n):
            for j in range(n):
                if to[i][k] and to[k][j]:
                    to[i][j] = True

    P = [0] * n
    ma = [n - 1] * n
    used = [False] * n
    for i in range(n):
        cc = 0
        for j in range(i + 1, n):
            if to[i][j]:
                cc += 1

        for k in range(n):
            if used[k]:
                continue
            cnt = [0] * n
            for j in range(i + 1, n):
                if to[i][j]:
                    cnt[min(k, ma[j])] += 1
                else:
                    cnt[ma[j]] += 1

            ok = True
            p = 0
            for j in range(n):
                if j > 0:
                    cnt[j] += cnt[j - 1]
                if used[j] or j == k:
                    cnt[j] += 1
                p += 1
                if cnt[j] > p:
                    ok = False
                    break

            if ok:
                P[i] = k + 1
                used[k] = True
                for j in range(n):
                    if to[i][j]:
                        ma[j] = min(ma[j], k)
                break
    print(*P)


for _ in range(int(input())):
    solve()

提出情報

提出日時
問題 C - Movie Theater
ユーザ rin204
言語 Python (PyPy 3.10-v7.3.12)
得点 700
コード長 1728 Byte
結果 AC
実行時間 1298 ms
メモリ 85828 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 1
AC × 27
セット名 テストケース
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 02_handmade_00.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 03_random_00.txt, 03_random_01.txt, 03_random_02.txt, 03_random_03.txt, 03_random_04.txt, 03_random_05.txt, 03_random_06.txt, 03_random_07.txt, 03_random_08.txt, 03_random_09.txt, 03_random_10.txt, 03_random_11.txt, 03_random_12.txt, 03_random_13.txt, 03_random_14.txt, 03_random_15.txt, 03_random_16.txt, 03_random_17.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 58 ms 76248 KiB
01_small_00.txt AC 74 ms 80596 KiB
01_small_01.txt AC 58 ms 76544 KiB
01_small_02.txt AC 67 ms 81108 KiB
02_handmade_00.txt AC 311 ms 85012 KiB
02_handmade_01.txt AC 342 ms 85064 KiB
02_handmade_02.txt AC 1150 ms 85220 KiB
02_handmade_03.txt AC 890 ms 84688 KiB
02_handmade_04.txt AC 1298 ms 85828 KiB
03_random_00.txt AC 88 ms 83172 KiB
03_random_01.txt AC 89 ms 82696 KiB
03_random_02.txt AC 99 ms 83288 KiB
03_random_03.txt AC 98 ms 83408 KiB
03_random_04.txt AC 120 ms 83968 KiB
03_random_05.txt AC 123 ms 83712 KiB
03_random_06.txt AC 176 ms 84632 KiB
03_random_07.txt AC 154 ms 84568 KiB
03_random_08.txt AC 1015 ms 85720 KiB
03_random_09.txt AC 661 ms 85440 KiB
03_random_10.txt AC 722 ms 85420 KiB
03_random_11.txt AC 628 ms 85416 KiB
03_random_12.txt AC 628 ms 85588 KiB
03_random_13.txt AC 602 ms 85184 KiB
03_random_14.txt AC 658 ms 85444 KiB
03_random_15.txt AC 709 ms 85408 KiB
03_random_16.txt AC 715 ms 85392 KiB
03_random_17.txt AC 609 ms 85548 KiB