結果

問題 No.1328 alligachi-problem
ユーザー tamatotamato
提出日時 2020-12-25 17:48:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 677 ms / 2,000 ms
コード長 1,907 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 81,988 KB
実行使用メモリ 135,248 KB
最終ジャッジ日時 2023-10-23 16:43:56
合計ジャッジ時間 19,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,760 KB
testcase_01 AC 36 ms
53,760 KB
testcase_02 AC 38 ms
53,760 KB
testcase_03 AC 36 ms
53,760 KB
testcase_04 AC 67 ms
70,984 KB
testcase_05 AC 68 ms
70,984 KB
testcase_06 AC 53 ms
64,648 KB
testcase_07 AC 70 ms
70,924 KB
testcase_08 AC 44 ms
59,276 KB
testcase_09 AC 647 ms
134,884 KB
testcase_10 AC 499 ms
111,284 KB
testcase_11 AC 644 ms
134,248 KB
testcase_12 AC 659 ms
134,932 KB
testcase_13 AC 622 ms
134,932 KB
testcase_14 AC 635 ms
134,864 KB
testcase_15 AC 497 ms
115,824 KB
testcase_16 AC 617 ms
134,864 KB
testcase_17 AC 619 ms
134,856 KB
testcase_18 AC 626 ms
135,092 KB
testcase_19 AC 645 ms
134,972 KB
testcase_20 AC 655 ms
135,248 KB
testcase_21 AC 635 ms
134,892 KB
testcase_22 AC 677 ms
133,984 KB
testcase_23 AC 503 ms
111,464 KB
testcase_24 AC 535 ms
127,292 KB
testcase_25 AC 585 ms
127,292 KB
testcase_26 AC 401 ms
125,684 KB
testcase_27 AC 406 ms
125,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    reqR = []
    reqB = []
    for i in range(1, N+1):
        C, X, Y = input().split()
        Y = int(Y)
        if X == "R":
            reqR.append((C, Y, i))
        else:
            reqB.append((C, Y, i))
    reqR.sort(key=lambda x: x[0])
    reqR.sort(key=lambda x: x[1])
    reqB.sort(key=lambda x: x[0], reverse=True)
    reqB.sort(key=lambda x: x[1])
    reqR.reverse()
    reqB.reverse()

    ans = []
    r = b = 0
    for _ in range(N):
        ok_r = 0
        ok_b = 0
        if reqR:
            if reqR[-1][1] == r:
                ok_r = 1
        if reqB:
            if reqB[-1][1] == b:
                ok_b = 1
        if ok_r == ok_b == 0:
            print("No")
            exit()
        if ok_r == 1 and ok_b == 0:
            c, _, i = reqR.pop()
            ans.append(i)
            if c == "R":
                r += 1
            else:
                b += 1
        elif ok_r == 0 and ok_b == 1:
            c, _, i = reqB.pop()
            ans.append(i)
            if c == "R":
                r += 1
            else:
                b += 1
        else:
            flg_r = flg_b = 0
            if reqR[-1][0] == "B":
                flg_r = 1
            if reqB[-1][0] == "R":
                flg_b = 1
            if flg_r == flg_b == 1:
                print("No")
                exit()
            if flg_r == 1:
                c, _, i = reqB.pop()
                ans.append(i)
                if c == "R":
                    r += 1
                else:
                    b += 1
            else:
                c, _, i = reqR.pop()
                ans.append(i)
                if c == "R":
                    r += 1
                else:
                    b += 1
    print("Yes")
    print(*ans)


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