結果

問題 No.1014 competitive fighting
ユーザー mkawa2mkawa2
提出日時 2020-03-24 08:52:20
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,233 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 149,388 KB
最終ジャッジ日時 2023-08-30 05:07:50
合計ジャッジ時間 42,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,244 KB
testcase_01 AC 80 ms
71,520 KB
testcase_02 AC 79 ms
71,512 KB
testcase_03 AC 79 ms
71,520 KB
testcase_04 AC 78 ms
71,124 KB
testcase_05 AC 1,399 ms
135,424 KB
testcase_06 AC 1,246 ms
135,512 KB
testcase_07 AC 1,332 ms
134,804 KB
testcase_08 AC 1,202 ms
134,808 KB
testcase_09 AC 1,225 ms
135,384 KB
testcase_10 AC 1,993 ms
149,388 KB
testcase_11 AC 248 ms
118,448 KB
testcase_12 AC 1,355 ms
135,240 KB
testcase_13 AC 707 ms
105,840 KB
testcase_14 AC 616 ms
104,472 KB
testcase_15 AC 765 ms
108,124 KB
testcase_16 AC 237 ms
83,164 KB
testcase_17 AC 402 ms
91,068 KB
testcase_18 AC 1,143 ms
126,912 KB
testcase_19 AC 1,294 ms
134,268 KB
testcase_20 AC 567 ms
100,660 KB
testcase_21 AC 1,009 ms
125,376 KB
testcase_22 AC 868 ms
111,520 KB
testcase_23 AC 455 ms
93,368 KB
testcase_24 AC 414 ms
93,740 KB
testcase_25 AC 244 ms
82,932 KB
testcase_26 AC 978 ms
125,248 KB
testcase_27 AC 376 ms
91,704 KB
testcase_28 AC 407 ms
91,000 KB
testcase_29 AC 158 ms
79,164 KB
testcase_30 AC 1,239 ms
132,820 KB
testcase_31 AC 1,059 ms
126,776 KB
testcase_32 AC 139 ms
78,268 KB
testcase_33 AC 143 ms
80,260 KB
testcase_34 AC 470 ms
112,008 KB
testcase_35 WA -
testcase_36 AC 410 ms
110,372 KB
testcase_37 AC 137 ms
79,064 KB
testcase_38 WA -
testcase_39 AC 321 ms
92,100 KB
testcase_40 AC 366 ms
101,732 KB
testcase_41 AC 291 ms
97,048 KB
testcase_42 AC 509 ms
118,388 KB
testcase_43 AC 125 ms
79,584 KB
testcase_44 AC 538 ms
115,648 KB
testcase_45 WA -
testcase_46 AC 136 ms
80,916 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 136 ms
79,040 KB
testcase_50 AC 511 ms
115,580 KB
testcase_51 AC 300 ms
98,756 KB
testcase_52 AC 121 ms
78,568 KB
testcase_53 AC 1,293 ms
134,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_right
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    def connect(j,l,r,sl=0,sr=-1,si=0):
        if l>=r:return 
        if sr==-1:sr=w
        if r<=sl or sr<=l:return
        if l<=sl and sr<=r:
            to[j+w-1].append(si)
            return
        sm=(sl+sr)//2
        connect(j,l,r,sl,sm,si*2+1)
        connect(j,l,r,sm,sr,si*2+2)

    def dfs(u,start=-1):
        if start==-1:start=u
        for v in to[u]:
            if vis[v]==start:
                dp[u]=inf
                break
            if vis[v]==-1:
                vis[v]=start
                dfs(v,start)
            if dp[v]==inf:
                dp[u]=inf
                break
            dp[u]=max(dp[u],dp[v])
        if u>=w-1:
            _,b,_,i=abci[u-w+1]
            if dp[u]!=inf:dp[u]+=b
            ans[i]=dp[u]

    inf=10**15
    n=II()
    abci=[]
    w=1<<(n-1).bit_length()
    to=[[] for _ in range(w-1+n)]
    for i in range(w-2+n,0,-1):to[(i-1)//2].append(i)
    for i in range(n):
        a,b,c=MI()
        abci.append((a,b,c,i))
    # aの小さい順に見ていってセグメント木に辺を張る
    abci.sort()
    aa=[]
    hp=[]
    for j,(a,b,c,i) in enumerate(abci):
        while hp and hp[0][0]<a:
            _,pj=heappop(hp)
            connect(pj,0,pj)
            connect(pj,pj+1,j)
        if b-c<a:
            k=bisect_right(aa,b-c)
            connect(j,0,k)
        else:
            heappush(hp,(b-c,j))
        aa.append(a)
    while hp:
        _, pj = heappop(hp)
        connect(pj, 0, pj)
        connect(pj, pj + 1, n)
    # dfsで最大スコアを求める
    dp=[0]*(2*w-1)
    vis=[-1]*(2*w-1)
    ans=[0]*n
    for u in range(w-1,w-1+n):
        if vis[u]!=-1:continue
        vis[u]=u
        dfs(u)
    # 答えの出力
    for x in ans:
        if x==inf:print("BAN")
        else:print(x)

main()
0