結果

問題 No.1014 competitive fighting
ユーザー mkawa2mkawa2
提出日時 2020-03-23 23:57:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,217 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 11,188 KB
実行使用メモリ 119,104 KB
最終ジャッジ日時 2023-08-28 15:07:32
合計ジャッジ時間 30,698 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,444 KB
testcase_01 AC 16 ms
8,440 KB
testcase_02 AC 16 ms
8,480 KB
testcase_03 AC 17 ms
8,556 KB
testcase_04 AC 16 ms
8,620 KB
testcase_05 AC 1,292 ms
86,888 KB
testcase_06 AC 1,230 ms
86,684 KB
testcase_07 AC 1,217 ms
86,852 KB
testcase_08 AC 1,211 ms
86,964 KB
testcase_09 AC 1,234 ms
86,872 KB
testcase_10 TLE -
testcase_11 AC 444 ms
68,776 KB
testcase_12 AC 1,272 ms
86,988 KB
testcase_13 AC 539 ms
45,296 KB
testcase_14 AC 503 ms
43,076 KB
testcase_15 AC 600 ms
47,508 KB
testcase_16 AC 34 ms
10,136 KB
testcase_17 AC 197 ms
23,560 KB
testcase_18 AC 1,004 ms
76,088 KB
testcase_19 AC 1,225 ms
85,080 KB
testcase_20 AC 392 ms
37,624 KB
testcase_21 AC 906 ms
71,272 KB
testcase_22 AC 703 ms
52,784 KB
testcase_23 AC 260 ms
26,672 KB
testcase_24 AC 268 ms
27,128 KB
testcase_25 AC 70 ms
12,748 KB
testcase_26 AC 905 ms
70,532 KB
testcase_27 AC 197 ms
23,368 KB
testcase_28 AC 231 ms
24,748 KB
testcase_29 AC 24 ms
8,904 KB
testcase_30 AC 1,207 ms
84,460 KB
testcase_31 AC 950 ms
72,280 KB
testcase_32 AC 23 ms
8,640 KB
testcase_33 AC 45 ms
12,148 KB
testcase_34 AC 442 ms
57,880 KB
testcase_35 WA -
testcase_36 AC 375 ms
55,096 KB
testcase_37 AC 28 ms
10,116 KB
testcase_38 WA -
testcase_39 AC 174 ms
25,856 KB
testcase_40 AC 317 ms
42,420 KB
testcase_41 AC 227 ms
35,256 KB
testcase_42 AC 517 ms
65,792 KB
testcase_43 AC 40 ms
11,880 KB
testcase_44 AC 481 ms
62,676 KB
testcase_45 WA -
testcase_46 AC 57 ms
14,552 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 31 ms
10,256 KB
testcase_50 AC 488 ms
64,072 KB
testcase_51 AC 287 ms
39,540 KB
testcase_52 AC 31 ms
10,504 KB
testcase_53 AC 1,257 ms
86,388 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 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 j in range(n):
        u=j+w-1
        if vis[u]!=-1:continue
        vis[u]=u
        dfs(u)
    # 答えの出力
    for x in ans:
        if x==inf:print("BAN")
        else:print(x)

main()
0